Context: I'm mainly a Javascript/Python developer and I'm doing Java just for schoolwork.
This is the code block that perplexes me.
public static void display(int a, int b) {
a = a+b-(b=a);
System.out.println(a);
System.out.println(b);
}
I encountered this code block in a practice exam I was doing. I expected this to be syntactically incorrect so I tried it with a compiler. No syntax errors appeared.
I don't understand how this is valid syntax. I get that the assignment operator would assign a
to b
and the result of a = a+b-(b=a)
would be the original value of a
. How does the compiler register b-(b=a)
as a valid piece of code?