Originally posted by Danny Duong:
Is there any subtle differences between the following two declarations?
int [] x = {1, 2, 3};
int [] x = new int[] {1, 2, 3};
Yes.
The first is implicit initialization of an array.
You use the new int[] to initialize the array object itself. That is, if you want your array to contain 3 elements, you make use of the new operator in this way,
int [] x;
x = new int[3];
Then, you can explicitly initialize each element of the array object, referenced by a primitive variable 'x'.
int [] x = new int[] {1, 2, 3}; // will
// give compile-time error
All the best Danny