| Author |
Anonymous Array
|
Bindesh Vijayan
Ranch Hand
Joined: Aug 21, 2001
Posts: 34
|
|
The code : When executed gets the following error: Array constants can only be used in initializers. print( {new Object(),new Object(),new Object()}, Array constants can only be used in initializers. {"A1","A2","A3","A4"} Am iam not using an initializer.JLS has the following statement Pls. help.. Thanks Bindesh Vijayan
|
 |
Rene Larsen
Ranch Hand
Joined: Oct 12, 2001
Posts: 1179
|
|
Try run the code like this: /Rene
|
Regards, Rene Larsen
Dropbox Invite
|
 |
Val Lee
Ranch Hand
Joined: Nov 27, 2001
Posts: 41
|
|
I modify your code: Anonymous array used like this:new int[]{1, 2, 3} or new int[10].
|
Val SCJP2 1.2<br />====>SCJD
|
 |
Bindesh Vijayan
Ranch Hand
Joined: Aug 21, 2001
Posts: 34
|
|
Guys, First things first, Thanks, and a correction I have missed some parts of the code as Rene points out.All I can say is it happens sometimes. And yes coming back to the problem,I knew this that the array should be given with new operator,thats not what I wanted to know ,but the specification provided by JLS . An array initializer is written as a comma-separated list of expressions, enclosed by braces "{" and "}". I want to be cleared on that... Thanks Bindesh
|
 |
Rene Larsen
Ranch Hand
Joined: Oct 12, 2001
Posts: 1179
|
|
This initialize an one dimension array: This initialize a two dimension array: /Rene
|
 |
 |
|
|
subject: Anonymous Array
|
|
|