ArrayList returns same element for every index
<p>I suspect that the value being returned is the last one I have added to my arraylist.</p>

<p>I've got a class <code>Game</code> where the following function gets executed...</p>

<pre><code>    public List&lt;M&gt; compute() throws CloneNotSupportedException{
    G chil = (G) this.clone();
    List&lt;Move&gt; Pm = new ArrayList&lt;M&gt;();
            Point p;

       for(/*condition*/){
                //p is defined up here.basically loops through all possible values of p.
            M m = pud.genM(chil, p);
            Pm.add(m);
        }
       return Pmoves;
}
</code></pre>

<p>The strange thing is I'm doing a print on the values being returned for <code>m</code> and they are as expected (different) but when I loop through the List that has been created each and every element is equal to the last element that was added. It appears that this last to be added element is overriding all previous children...</p>

<p>The variable <code>pud</code> is of type <code>User</code>. The function being called is...</p>

<pre><code>public M genM(GameState g, boardPoint p){
    M m; // a move
    for(/*condition*/){
        m = new M(/*parameters*/);
        return m;
    }
    return null;
}
</code></pre>

<p>I've simplified this class down a fair bit, there's some if else conditions and an additional for loop but I took them out of this example because they're kind of messy and most likely irrelevant.</p>

<p>The object <code>M</code> is defined as...</p>

<pre><code>    public M(String type, Point fPos, Point tPos, String input, G g){
    this.type = type;
    this.toPos = toPos;
    this.fromPos = fromPos;
    this.uInput = uInput;
    result = new G(g);
            //value of G gets edited here.
}
</code></pre>
