This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array Problem

 
Rahul Pawar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends ,
if i mention :
int arr[] = new int{1,2 3,4}; =>it's illegeal
int arr[] = new int[]{1,2,3,4};=>it's legal
can anybody explain me y is it so ?
rahul
 
lee dalais
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after the 'new' keyword is used in an array declaration, [] is expected to define the dimension(size), so:
int arr[] = new int{1,2 3,4}; is illegal
but below is a legal array construction statement:
int arr[] = new int[]{1,2,3,4};
look here in the JLS
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic