Monday, June 19, 2006

Anonymous array declaration

Anonymous arrays have to be assigned to the variables at the time of declaration of varaible itself. Assigning to the variable after variable declaration is not possible
ie.,
int[] i = {1,2,3} is fine.
But,
int[] i;
i = {1,2,3} is compiler error.
This restriction at the time of method invocation is valid, since we don't know the type of array(overloading issue). But for assignment the left side variable type is known. So, why should it be not possible to cast the anonymous array {1,2,3} to int[] and assign to variable.

No comments: