title: Last added object overrides my ArrayList
body: <p>Last objected added to the ArrayList overrides all elements in the ArrayList and I can't figure it out why.. even after reading all problem related topics on web. </p>
  
  <p>I create new object each iteration? and all fields (move, board, color) are protected (I can't change that since I'm using a chessboard framework).</p>
  
  <p>I haven't found the solution on web because my fields ain't static and I also create a new object after each iteration.</p>
  
  <pre><code>public String solve(String fen) {
      Chessboard cb = Chessboard.getChessboardFromFEN(fen);
      return solve(cb);
  }
  
  private String solve(Chessboard cb){
   ArrayList&lt;Chessboard&gt; prioritetna = new ArrayList&lt;&gt;();
   for(int i = 0; i &lt; 10; i++){
    cb.makeMove(cb.getMoves().get(i));
    prioritetna.add(new Chessboard(cb.getBoard(), cb.getColor(), 
    cb.getMovesLeft()));
    cb.reverseMove(cb.getMoves().get(i));
   }
   return "";
  }
  </code></pre>
  
  <p>And I use this framework that is made of three classes for Chessboard implementation: 
   1. Chessboard: <a href="https://pastebin.com/CqgHLCXM" rel="nofollow noreferrer">https://pastebin.com/CqgHLCXM</a>
   2. Move: <a href="https://pastebin.com/g2wr16TP" rel="nofollow noreferrer">https://pastebin.com/g2wr16TP</a>
   3. Rules: <a href="https://pastebin.com/HEznyECY" rel="nofollow noreferrer">https://pastebin.com/HEznyECY</a></p>
  
  <p>I've also rewrote code with no framework dependencies and it works.. so i guess this is a framework problem.</p>
  
  <p>Framework is also available as a JAR: <a href="https://ufile.io/c7n3o" rel="nofollow noreferrer">https://ufile.io/c7n3o</a></p>
  
  <p>public static void main(String[] args) {</p>
  
  <pre><code>    ArrayList&lt;Object&gt; list = new ArrayList&lt;&gt;();
      Random rand = new Random();
  
      for(int i = 0; i &lt; 5; i++){
          list.add(new Object(rand.nextInt(50) + 1, rand.nextInt(50) + 1));
      }
  
      for(int i = 0; i &lt; 5; i++){
          System.out.println(list.get(i).getOne());
      }
  
    }
  
  
  public class Object {
    protected int one;
    protected int two;
  public Object(int one, int two){
      this.one = one;
      this.two = two;
  }
  
  public int getOne() {
      return one;
  }
  
  public void setOne(int one) {
      this.one = one;
  }
  
  public int getTwo() {
      return two;
  }
  
  public void setTwo(int two) {
      this.two = two;
  }
  </code></pre>
  
  <p>}</p>