Copy address of an object in a Class to an argument, so I can make changes to the object later
<p>In my original code, I'm adding nodes to a tree. My goal is to somehow get access to the last node that I added in the tree (my idea was to create another object that will point to the last object (node in my original example)). </p>

<pre><code>public class RandomSubClass 
{
    int firstNum;
}    
</code></pre>

<hr>

<pre><code>import java.util.LinkedList;

public class RandomClass 
{
    LinkedList&lt;RandomSubClass&gt; myListOfObjects = new LinkedList&lt;RandomSubClass&gt;();

    void addItem(int firstNum, RandomSubClass toBeReturned)
    {       
        RandomSubClass o1 = new RandomSubClass();
        o1.firstNum = firstNum;
        myListOfObjects.add(o1);

        // Here I was thinking that 'toBeReturned' will get same address as
        // 'o1', and by changing 'toBeReturned' (in main), values in 'o1' change
        //
        toBeReturned = o1;

        // This following commented code worked, 
        // but I can't use it in my original code.
        //
        // The reason I can't use it is because when I add a node to a tree, 
        // I start at the root and trace the new node's way to a new leaf, 
        // which makes it hard to do (simply) that.
        //
        //toBeReturned.firstNum = firstNum;
        //myListOfObjects.add(toBeReturned);
    }   
}
</code></pre>

<hr>

<pre><code>public class Main 
{
    public static void main(String[] args) 
    {
        RandomClass myList = new RandomClass();

        RandomSubClass r1 = new RandomSubClass();
        RandomSubClass r2 = new RandomSubClass();

        myList.addItem(1, r1);
        myList.addItem(2, r2);

        // I would like to do that, and see changes in the node in 'myList'
        //  
        r1.firstNum = 10;
        r2.firstNum = 20;
    }
}
</code></pre>

<p>I want to check something about the node after I add it to the tree, and if it satisfies some condition, I want to change a flag for that node.</p>

<p>I can re-trace the node again (starting at root), but my tree might get huge at some point and it will take time. So if I get the address of that node when I add it, and after I check my condition, I can modify the flag at that address, knowing that it will change the flag at that node (last added).</p>
