您面临的问题称为协方差。
List<GenericClass<String>> stringy = ...List<GenericClass<?>> generic = stringy;generic.add(new GenericClass<Integer>());
如果这不是编译错误,那么最后一行代码将是可能的。
您可以通过以下方法解决错误:
List<? extends GenericClass<?>> generic = stringy;
但您也不能使用,
add因为您真的不知道什么
? extendsGenericClass<?>(再次是协方差)。在这种情况下,您只能通过List进行枚举并期望
GenericClass<?>。



