How to implement int in/out params in java
<p>Apologies for asking such a primitive question. </p>

<p>I wrote a function which took one parameter; this parameter was supposed to be an in/out parameter. </p>

<p>After debugging, I realized, since there are no explicit reference types in java, I should probably use Integer object (instead of int primitive) as the parameter type. So I changed my function:</p>

<pre><code>boolean getNextFoo(int currentFoo) {
    currentFoo = currentFoo + 1;
}
</code></pre>

<p>to:</p>

<pre><code>boolean getNextFoo(Integer currentFoo) {
    currentFoo = currentFoo + 1;
}
</code></pre>

<p>After checking the execution in the debugger, I realized this has the same results as the previous. That is, the object that I'm passing into <code>getNextFoo()</code> does not change. </p>

<p><strong>Question 1</strong>: How to I achieve in/out parameters with Java (more specifically for primitive types). I thought (pardon me) that objects are always passed by reference.</p>

<p><strong>Question 2</strong>: I was checking on the internet for answers and read that Integer is immutable. I understand immutable means constant. If so, why doesn't the compiler (interpreter?) complain when I do <code>currentFoo = currentFoo + 1</code> within the <code>getNextFoo</code> function?</p>

<p><strong>PS</strong>: I see in the debugger that Integer object is actually not being passed to <code>getNextFoo</code>, instead the value of <code>Integer.valueOf</code> is being passed into <code>getNextFoo</code> which is leaving me even more confused.</p>
