title: Java: Adding to an array list
body: <pre><code>public class Maze
  {
      public static final int ACTIVE = 0;
      public static final int EXPLORER_WIN = 1;
      public static final int MONSTER_WIN = 2;
      private Square[][] maze;
      private ArrayList&lt;RandomOccupant&gt; randOccupants;
      private Explorer explorer;
      private int rows;
      private int cols;
  
  public Maze(Square[][] maze, int rows, int cols, int numTreasures, int numMonsters, String name)
  {   
      int i;
      this.maze = maze;
      this.cols = cols;
      this.rows = rows;
  
      randOccupants = new ArrayList&lt;RandomOccupant&gt;();
  
    for (i = 0; i &lt; numTreasures; i++) 
    {
      randOccupants.add(i) = new Treasure(this);  //COMPILE ERROR
    }...
  </code></pre>
  
  <p>Why can't I add this to the arraylist? I believe the java docs says that I'm doing this correctly.</p>