使用Java进行了多年编程之后,我仍然不明白这一点!
定义了顶级类
public abstract class GenericCache<K, T, P> {
public ArrayList<T> getAll() {}
public T getSafe(K a_id) {}
}
子类是
public class SKUTypeCache<T extends SKUType, P> extends GenericCache<Integer, T, P> {
}
当我尝试使用它
SKUTypeCache l_cache = getTheCache();
for (SKUType t : l_cache.getAll()) {
}
我在for循环上收到编译错误:“不兼容的类型:无法将对象转换为SKUType”。为什么?使用getSafe()有类似的问题。