1
我想一個兒童類的類對象添加到一組父類對象的:無法添加children.class設置parent.class
public class Main {
public static void main(String[] args) {
Set<Class<? extends A<?>>> set = new HashSet<>();
set.add(C.class); //this does not work
}
public abstract class A<T> {
}
public abstract class B<T, V> extends A<T> {
}
// Set<T> could be any other class, it is for demonstration purpose.
public class C<T> extends B<Set<T>, Set<T>> {
}
}
我得到以下錯誤:
The method add(Class<? extends Main.A<?>>) in the type Set<Class<? extends Main.A<?>>> is not applicable for the arguments (Class<Main.C>)
如果我刪除'?'從A代碼編譯,但我不明白爲什麼。有人可以解釋爲什麼「添加」不起作用嗎?