我在这里查看了这个问题。这个问题的问题是这一行:
Integer i3 = (Integer) -128; /*** Doesn't compile ***/
正如一些答案所说:
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
答案对我来说是正确的。现在在 groovy 中,我尝试了与之前相同的代码:
Integer i3 = (Integer) -128; /*** compiles!!! ***/
甚至这行代码也可以编译:
Integer i3 = (Integer) -(128); /*** compiles ***/
Groovy 如何执行此操作?所有JVM语言都这样做吗?在 Groovy 的情况下,幕后发生了什么。
这不会违反 Java 规则吗?有点糊涂。
作为参考,我在此处标记了有效的 Groovy 代码
提前致谢。