I had a look at this question here. The problem with this question is this line:
Integer i3 = (Integer) -128; /*** Doesn't compile ***/
As some of the answer's say's:
The compiler interprets the - as the two-arg minus operator, i.e. it's trying to subtract 128 from some other number named Integer, but there's no such variable in scope
The answers look correct for me. Now in groovy I tried the same code as such before :
Integer i3 = (Integer) -128; /*** compiles!!! ***/
even this code of line compiles:
Integer i3 = (Integer) -(128); /*** compiles ***/
How does Groovy performing this operation? Does all Jvm languages does this? Whats happening behind the scene's in case of Groovy.
Does this doesn't break Java rule? Bit confused.
For reference I have tagged the working Groovy code here
Thanks in advance.
Groovy isn't Java.
It doesn't have to follow Java's specification and in this case ... doesn't.
Edit for clarity: I think what's confusing you is that you don't understand that these are two different languages. Both the Groovy compiler and the Java compiler output bytecode from your source code which then runs on the JVM (Java Virtual Machine). The JLS (Java Language Specification) applies to the Java language only. Groovy does not have to adhere to it.