求助:关于Java泛型通配符
和各位请教一个关于泛型通配符的问题,以下是程序:
import java.util.*;
import java.io.*;
class A
{
int a;
public A()
{
a=5;
}
}
class B extends A implements Serializable
{
int b;
public B()
{
super();
b=15;
}
}
public class Test
{
public static void main(String[] args)
{
ArrayList<A> list1=new ArrayList<A>();
ArrayList<? super B> list2=list1;
list2.add(new A());
list2.add(new B());
}
}
上述程序中,语句"list2.add(new A());"出错,编译器提示:
The method add(capture#1-of ? super B) in the type ArrayList<capture#1-of ? super B> is not applicable for the arguments (A)
这其中的原因是什么,请高人指点迷津,非常感谢!