How to change the reference in a function
<p>In the following code snippet p is a node in a binary search tree, if the left child of p is not null I want to change p to point to its left child, but java is pass-by-value, when the function returns the structure of the tree remains unchanged. </p>

<pre><code>void remove(BSTNode p)
{
    if(p.ch[0]==null)
        p=p.ch[0];
}
</code></pre>

<p>Actually I want to implement something like the following C++ code:</p>

<pre><code>void remove(BSTNode* &amp;p)
{
    if(p-&gt;ch[0]==NULL)
        p=p-&gt;ch[0];
}
</code></pre>

<p>For other reasons I don't want to use the following way to return p.ch[0] and set p after every call to remove.</p>

<pre><code>BSTNode remove(BSTNode p)
{
    if(p.ch[0]==null)
        return p.ch[0];
}
</code></pre>

<p>How can it be done?</p>
