This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Illegal Start of Expression

 
AnujS Sharma
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am getting an error "Illegal Start of Expression" on the following code:



Here, NoOfJumps is a method defined in a class which does not have the main method. This method accepts 4 arguments namely

1)Integer
2)Integer
3)Integer
4)Integer Array


Can someone please explain why this error is coming up and what is the resolution for this?



Thanks
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12017
24
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
look at the previous line, and make sure it is ended correctly. Also, make sure your brackets are all correct. sometimes you are missing one, and the parser gets all confused.
 
AnujS Sharma
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so.

Here is the full code.


 
Rameshwar Soni
Ranch Hand
Posts: 247
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to me instead of this try this
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rameshwar is right. You can use the short {} initialization only directly when declaring: You can't use it when calling a method, and not even when giving an existing array variable a new value.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47244
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the ellipsis operator allows you to change the array parameter to varargs, then you can write 1, 2, 3 rather than {1, 2, 3}.
 
AnujS Sharma
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the help. Learnt something today.

 
Campbell Ritchie
Sheriff
Pie
Posts: 47244
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic