The following code block
class Main {
public static void main(String[] args) {
System.out.println( + 1);
}
}
Compiles on java 1.8.
When this code is run 1
is printed.
Same with System.out.println(+ + 1);
However ++1
fails to compile.
+ + "str"
fails to compile.
+ + true
fails to compile.
So it looks like it is supported only for int, long and double.
What is the reason that this expression is valid for the above data types?