假设有一个超类America和它的两个子类SouthAmerica和NorthAmerica。
第一种情况
对于数组:
第一种情况
对于数组:
America[] am = new SouthAmerica[10]; //why no compiler error
am[0]= new NorthAmerica(); //ArrayStoreException at RunTime
情况二
在泛型中:
ArrayList<America> ame = new ArrayList<SouthAmerica>(); //this does not compile
我的问题不是为什么第二种情况不能编译,而是为什么第一种情况可以编译。我的意思是,除了基本的数组类型和子数组对象之外,还有什么可以做到这一点?