posted 23 years ago
Hello.
consider the following code:
class A {}
class B extends A {}
////some code here
/// in main()
int[] i = new int[10];
long[] l = new long[10];
// l = i; // this won't compile even though int can be assigned to long.
A[] a = new A[10];
B[] b = new B[10];
a = b; // this WILL compile because every element of a can be assigned to b
/////
I wanna make sure I understand this clearly. this happens because
array i and array l have primitive data types as elements. if elements of arrays are all object reference types and as long the elements of one array can be assigned to another, the whole array can be assigned to another array. is this correct? and this rule doesn't hold for array of primitive types.
thanks for the help! much appreciated.
chun