Java 在类型列表中添加(?扩展客户)的方法<;?扩展客户>;不适用于参数(客户)
使用Java 在类型列表中添加(?扩展客户)的方法<;?扩展客户>;不适用于参数(客户),java,generics,collections,Java,Generics,Collections,使用list可能重复的list可能重复的 public class GenericInheritance { public static void main(String[] args) { List<? extends Customer> custs2=new ArrayList<LocalCustomer>(); custs2.add(new Customer()); // Error
list可能重复的list可能重复的
public class GenericInheritance {
public static void main(String[] args) {
List<? extends Customer> custs2=new ArrayList<LocalCustomer>();
custs2.add(new Customer()); // Error
custs2.add(new LocalCustomer("ABC")); // Error
((List<Customer>)custs2).add(new LocalCustomer("PQR")); // No Error
}
}