Java 不允许我在此类中添加类型声明的子类
public class Exam<T> {
public void set(Holder<? super T> hold){
}
public T get(Holder<? extends T> holder){ return holder.get();}
public static void main (String[] args){
Exam<Question> eq = new Exam<Question>();
eq.set(new Holder<Identification>());
}
}
其中标识是问题的子类。
这就是我的持有人班级的样子
public class Holder<T> {
T item;
public void set(T item){ this.item = item; }
public T get(){return item;}
}
错误
The method set(Holder<? super Question>) in the type Exam<Question> is not applicable for the arguments (Holder<Identification>)