title: Polymorphism and ArrayLists in Java
body: <p>I have a class <code>Cell</code> and a class <code>Neighbour</code> extending <code>Cell</code>. But I get an error when I try to pass an <code>ArrayList&lt;Neighbour&gt;</code> to a function expecting an <code>ArrayList&lt;Cell&gt;</code>. What have I missed?</p>
  
  <pre><code>class Cell {
      PVector pos;
  
      Cell(PVector pPos) {
          pos = pPos.get();
      }
  }
  
  class Neighbour extends Cell {
      int borders = 0;
  
      Neighbour(PVector pPos) {
          super(pPos);
      }
  }
  
  private int inSet(PVector pPos, ArrayList&lt;Cell&gt; set) {
      [...]
  
      return -1;
  }
  
  [...]
  
  ArrayList&lt;Neighbour&gt; neighbours = new ArrayList&lt;Neighbour&gt;();
  PVector pPos = new PVector(0, 0);
  
  [...]
  
  inSet(pPos, neighbours);
  </code></pre>
  
  <p>The last line throws the error `The method iniSet(PVector, ArrayList) is not applicable for the arguments (PVector, ArrayList);</p>
  
  <p>Thanks for your help!</p>