Decrement (or increment) operator in return statement in Java
<p>I was implementing pagination in my web application (using Spring and Hibernate) where I needed the stuff something like the following.</p>

<pre><code>public static int deleteSingle(long totalRows, long pageSize, int currentPage)
{
   return totalRows==currentPage*pageSize-pageSize ? currentPage-- : currentPage;
}
</code></pre>

<p>Suppose, I invoke this method from somewhere as follows.</p>

<pre><code>deleteSingle(24, 2, 13);
</code></pre>

<p>With these arguments, the condition is satisfied and the value of the variable <code>currentPage</code> (i.e 13) minus 1 (i.e 12) should be returned but it doesn't decrement the value of <code>currentPage</code>. It returns the original value which is 13 after this call.</p>

<hr>

<p>I had to change the method like the following for it to work as expected.</p>

<pre><code>public static int deleteSingle(long totalRows, long pageSize, int currentPage)
{
    if(totalRows==currentPage*pageSize-pageSize)
    {
        currentPage=currentPage-1;   //&lt;-------
        return currentPage;          //&lt;-------
    }
    else
    {
        return currentPage;
    }
}
</code></pre>

<p>So why doesn't it decrement the value by 1 with the decrement operator - <code>currentPage--</code>? Why does it need - <code>currentPage=currentPage-1;</code> in this scenario?</p>
