是.Java Arrays是同构的,因为当您在Java中声明任何数组时,您必须声明其type。
例如:
int arr[]; //type is int
String arr[]; //type is String
float arr[]; //type is float现在,如果您尝试在声明的数组中存储任何其他数据类型,则会出现编译时错误。
例如:
int arr=new int[5];
arr[0]="I am a String not int"; //compile time error但ArrayList是Collection的一部分,他们持有Objects,而不是任何具体data-type [如果我们不是在谈论generics],因为在Java中的每一件事情,直接或间接地从Object class继承的,因此它不会给你compile-time error,type检查将在run-time上。
例如:
ArrayList al=new ArrayList();//type is Object
al.add("I am a String"); //Bacause String class in inherited from Object Class
al.add(1);//the int 1 will first autobox into Integer class then stored in al ArrayList.Now bacause Integer class is also inherited from Object class,it will*/ allow you to store
al.add(UserDefinedClass); //because every User defined class is also inherited from Object class,so it will also allow you.现在你注意到了,因为我们还没有定义ArrayList al的任何数据类型,但我们仍然存储不同的类型值:这就知道为什么ArrayList存储Object不是特定的数据类型,因此它们是异构的而不是同类的。