Running the following in a 1.8 console:
def accessories = null
final int prime = 31;
int result = 1;
result = prime
* result
+ ((accessories == null) ? 0 : accessories
.hashCode());
I get a compilation error stating:
unexpected token: * at line: 5, column: 13
Yet, when I move "* result" up to the previous line, it compiles and runs cleanly. I've searched to try to find an explanation, but have had no luck thus far. Can someone explain?
def accessories = null
final int prime = 31;
int result = 1;
result = prime * result
+ ((accessories == null) ? 0 : accessories
.hashCode());
Why the Bash unexpected token syntax error occurs? As the error suggests this is a Bash syntax error, in other words it reports bad syntax somewhere in your script or command. There are many things that can go wrong in a Bash script and cause this error.
Example 2: An unexpected token ‘, ‘occurs after i=0 which javascript cannot recognize.We can remove error here by removing extra. Example 3: An unexpected token ‘)’ occur after i++ which JavaScript cannot recognize.We can remove error here by removing extra ).
Similarly, unnecessary use of any token will throw this type of error. We can remove this error by binding by following the programming rules of JavaScript.
Example 1: It was either expecting a parameter in myFunc (mycar, ) or not, .So it was enable to execute this code. Example 2: An unexpected token ‘, ‘occurs after i=0 which javascript cannot recognize.We can remove error here by removing extra.
Because Groovy's statements are not delimited by ;
, but rather by line break. It can't know the line below is a continuation of the statement on the line above. You can escape the line break:
int i = 10 \
* 9
assert i == 90
Update:
Actually Groovy does identify some statements as from the above line. At least the dot is recognized:
assert [1, 2]
.join("")
.padLeft(4, "a") == "aa12"
And a statement with either +
, -
and ~
(and maybe more) could be methods:
def m = "aa"
- m // fails with "No signature of method: java.lang.String.negative()"
This is necessary because otherwise the parser for Groovy would have to do a lot more work.
There are lots of places ie:
String s = "tim"
+ "_yates"
Where it would be possible for the parser to work out what you meant, but in all of them, I believe it would involve backtracking (or implementing a two pass parse) which is slow
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With