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