posted 19 years ago
hi jerry,
First, be clear with what is an Dimension expression & an initializer ?
DIMENSION EXPRESSION:
consider,
int[] a = new int[10];
here, the expression "new int[10]" is called the dimension expression. It creates an array of size 10.
the thumb rule is: SIZE OF ARRAY MUST BE SPECIFIED WHEN WE CREATE IT.
INITIALIZER:
consider,
int[] a = {1,2,4};
here, the expression "{1,2,4}" is called the initializer. It creates an array of size 3. what? But where is size mentioned ? that's the trick .. the size is automatically taken from the number of elements within { }.
So, now read dan's sentence ..what he really means is that we cannot have a stmt like following :
int[] a = new int[5] {1,2,3,4,5};
Now, can u understand that the examples u have posted are also irrelevant !!!
example 1 is wrong because size is mandatory. Not because of dan's statement.
bye,
senthil.