阅读背景:

数组如何在Java中“记住”它们的类型?

来源:互联网 

Consider the following code:

考虑下面的代码:

class AA { }

class BB extends AA { }

public class Testing {

    public static void main(String[] args) {
        BB[] arr = new BB[10];
        AA[] arr2 = arr;

        BB b = new BB();
        AA a = new AA();
        arr2[0] = a; // ArrayStoreException at runtime
        arr2[1] = b;

        List<BB> listBB = new ArrayList<>();
        List listAA = listBB;
        listAA.add("hello world.txt");

    }
}
class



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: