I\'m trying to get deeper with post and pre incrementors but am a bit stuck with the following expression :
public static void main(String[] args) {
int i
I suggest the following: format the code differently, so that there's only 1 statement per line, e.g.
@Test
public void test() {
int i = 0;
i =
i+=
(
++i
+
(
i+=
2
+
--i
)
-
++i
);
System.out.println(i); // Prints 0 instead of 5
}
Then run it under the debugger and press F5 ("Step into") always. This will help you to understand in which order items get evaluated:
int i=0;i=: ... (needs to wait for result of calculation A)i+= ... (needs to wait B)++i: i=1i+= ... (needs to wait C)2+--i: i=0-++i: i=4 and operand of - is also 4Line 10 will always make the result of line 3 0, so the initial value of i will never be changed by the whole operation.