title: Java Generic with ArrayList <? extends A> add element
body: <p>I have classes <code>A</code>, <code>B</code>, <code>C</code> and <code>D</code> where <code>B</code> extends <code>A</code>, <code>C</code> extends <code>A</code> and <code>D</code> extends <code>A</code>.</p>
  
  <p>I have the following <code>ArrayList</code>s each with a few elements in them:</p>
  
  <pre><code>ArrayList&lt;B&gt; b;
  ArrayList&lt;? extends A&gt; mix = b;
  </code></pre>
  
  <p>I intended for the variable <code>mix</code> to contain elements of type <code>B</code>, <code>C</code> or <code>D</code>. I tried to add an element of type <code>C</code> into <code>mix</code> like this:</p>
  
  <pre><code>mix.add(anElementOfTypeC);
  </code></pre>
  
  <p>But the IDE doesn't allow me to do so and it says:</p>
  
  <blockquote>
    <p>anElementOfTypeC cannot be converted to CAP#1 by method of invocation
    conversion where CAP#1 is a fresh type-variable: CAP#1 extends A from
    capture of ? extends A</p>
  </blockquote>
  
  <p>Did I use the <code>&lt;? extends A&gt;</code> correctly? How can I resolve this?</p>