Post Decrement in Java
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/11086765/decrement-in-java">Decrement in java</a>  </p>
</blockquote>



<p>I was looking at this question, <a href="http://stackoverflow.com/questions/11086765/decrement-in-java#11086765">Decrement in java</a> and it piqued my curiosity. I understand how post/pre increment/decrement work, but I want to know why it works the way it does in that particular situation.</p>

<p>For example,</p>

<pre><code>int x = 5;
x--;
</code></pre>

<p>Will very obviously set x to be 4. But if you do,</p>

<pre><code>x = x--;
</code></pre>

<p>x will be 5 still (as discovered by the poster of the referenced question). From my understanding of post decrement, it returns the value before it modifies it. So what I expect to happen would be that <code>x = 5</code> happens first. (keeping consistent with the above). Then, x is decremented, so in my mind, <code>x--;</code> would run, which in the above clearly sets x to be 4.</p>

<p>I mean, yes, it's easy enough just to do <code>x--;</code> but I would like to understand why Java's post decrement works this way.</p>

<p>I tried the code below and it worked exactly as expected.</p>

<pre><code>int x = 5;
int y = x--;
</code></pre>

<p><code>y</code> was set to 5 and <code>x</code> was properly decremented. Why doesn't the same happen for <code>x = x--;</code>? </p>
