File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Anonymous Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Anonymous Array" Watch "Anonymous Array" New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Anonymous Array