Win a copy of Functional Reactive Programming this week in the Other Languages 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