File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array Initialization

 
sentil kumar
Ranch Hand
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int [] a1;
a1= {2,2,2};
why the above is not compiled. but the below code works fine.
a1= new int[]{2,2,2};
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sentil,
Rather than asking why?Just burn that for the array creation by using syntax

The array declaration ,creation(on the fly... there is no new operator) and initialization can not be separated out.You can not image an object like {2,2,2} which is to be refered by a1 and for

The array declaration may be separated out from the creation and initilization but the creation and initialization can not be separated out.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic