public void test4()
System.out.println(i); //prints 0
System.out.println(m=i++); //prints 0
System.out.println(m); //prints 0
System.out.println(i); //prints 1
This shows the sublety here in this example. Before I stated that the postfix increment happens after the assignment. (expressions are evaluated from left to right).
Found this in the online tutorial at: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arithmetic.html
" op++ : Increments op by 1; evaluates to the value of op before it was incremented
++op : Increments op by 1; evaluates to the value of op after it was incremented "
So in the expression i=i++;, i does increment, but gets evaluated to the value it was before it was incremented, which is 0.
0 gets assigned to the variable i (i=i++), which overwrites the original value of i which was 1. This is very tricky, but basically in how it gets evaluated, the value 1 gets overwritten with the value 0, due to how postfix notation evaluates the expression.
Hope this helps.