• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Anonymous Array

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try run the code like this:

/Rene
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I modify your code:

Anonymous array used like this:new int[]{1, 2, 3}
or new int[10].
 
Bindesh Vijayan
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This initialize an one dimension array:

This initialize a two dimension array:

/Rene
 
bacon. tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic