This was probably asked somewhere but I couldn't find it. Could someone clarify why this code compiles and prints out 1
?
long i = (byte) + (char) - (int) + (long) - 1; System.out.println(i);
It's being parsed as this:
long i = (byte)( +(char)( -(int)( +(long)(-1) ) ) );
where all the +
and -
operators are unary +
or -
.
In which case, the 1
gets negated twice, so it prints out as a 1
.
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