Hi:
I'm new to the forum; just started to study so I'm definitely
a greenhorn
The output of 3 in your example is confusing:
<pre>
int i = 3;
i = i++;
System.out.println(i);
</pre>
In the JLS Section 15.4.1 states:
At run time, if evaluation of the operand expression completes abruptly, then the postfix increment expression completes abruptly for the same reason and no incrementation occurs. Otherwise, the value 1 is added to the value of the variable and the sum is stored back into the variable.
You would expect i to equal 4 after the increment is applied.
It does say the SUM is stored back into the variable. I think
the problem is that you're doing an assignment:
<pre>
i = i++;
</pre>
when i++
is an implicit assignment If you re-write the code to:
<pre>
int i = 3;
i++;
System.out.println(i);
</pre>
The output is the expected 4.
The assignment operator in the original example must somehow
cause the postfix operation to
complete abruptly; causing it to fail.
Does that make sense?