public static void main(String[] args) {
int x = 1 + + + + + + + + + 2;
System.out.println(x);
}
I can compile above method. Is there any explanation about the allowed multiple "+" operator?
It's addition, then the unary plus operator repeated. It's equivalent to the following:
int x = 1 + (+ (+ (+ (+ (+ (+ (+ (+ 2))))))));
The reason is that + can act as a unary operator, similar to how - can be the negation operator. You are just chaining a bunch of unary operators together (with one final binary addition).
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