Count ++ Java in the pit

Recently made a question, very easy to fall into the trap.

When the count initial value is 0, count = count ++; and count = ++ count; run out of the result is not the same. The results count = count ++ is still run out 0;

This is because the JVM runtime will count variable to be copied to the temporary variable region, the count value of 0 into the operand stack, count = 0 In this case, the count ++ is added after a first assignment, the local variable table to count plus 1, then the operand stack and then pop 0 is assigned to the local variable table. Therefore, although the count to 1, but the final count is still assigned value is 0.

Published 47 original articles · won praise 7 · views 20000 +

Guess you like

Origin blog.csdn.net/floraruo/article/details/103990473