Originally posted by Badri Narayanan:
Why does this code is not legal ?
Does this mean array dimension are read from left to right ?(Associativity for [] operator).I don't find a reason or simply could understand the reason.Can somebody gimme me more example to explain
Thanks
-Badri
Okay, this code:
int [][] testArray = new int[3][4];
Means to allocate an array of size 3, of int arrays. And in each element of this array, allocate an array of size 4, of ints.
This code:
int [][] testArray = new int[3][];
Means to allocate an array of size 3, of int arrays. But don't bother allocating each element of this array. Instead just set it to null.
So, if this code:
int [][] testArray = new int[][3];
was legal. What do you think the compiler should do? Should it allocate an unknown number of arrays of size 3, of ints. And assign it to elements of an array that won't be allocated?
Henry
[ December 14, 2006: Message edited by: Henry Wong ]