I'm curious why this simple program could be compiled by java using IntelliJ (Java 7).
public class Main { public static void main(String[] args) { int e = + + 10; System.out.println(e); } }
The output is still 10. What is the meaning of + + 10
?
Java code needs to be compiled twice in order to be executed: Java programs need to be compiled to bytecode. When the bytecode is run, it needs to be converted to machine code.
To make matters worse, the associated Java compile error poorly describes the source of the problem. To fix the problem, simply make the "I" in "Integer" lowercase and make the "s" in "system" uppercase: int x = 10; System.
The Java source code first compiled into a binary byte code using Java compiler, then this byte code runs on the JVM (Java Virtual Machine), which is a software based interpreter. So Java is considered as both interpreted and compiled. The compiled byte code allows JVM to be small and efficient, and fast performing.
It is the unary plus, twice. It is not a prefix increment because there is a space. Java does consider whitespace under many circumstances.
The unary plus basically does nothing, it just promotes the operand.
For example, this doesn't compile, because the unary plus causes the byte
to be promoted to int
:
byte b = 0; b = +b; // doesn't compile
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