Java Pass by value, Advantage or Disadvantage?
<p>Java is pass by value. What if I need a pass by reference. For example in the following code I need a pass by reference mechanism.</p>

<pre><code>public class BinaryTree {
    public TreeNode root;

    public BinaryTree(){
        root = null;
    }

    public TreeNode insert(TreeNode temp,int x){
        if(temp == null){
            temp = new TreeNode();
            temp.key = x;
            temp.left = temp.right = null;
            return temp;
        }
        if(temp.key &gt; x)
            temp.left = insert(temp.left,x);
        else if(temp.key &lt; x)
            temp.right = insert(temp.right,x);
        return null;
    }
 }
</code></pre>

<p>When <code>insert</code> is called with <code>root</code>, I need <code>root</code> to be passed as a reference so as to change its value. But this does not happen in Java, since it's pass by value. In C/C++ the above could be easily achieved. Don't you think that this is a drawback of Java? How could such problems be solved in Java?</p>
