title: Covariance of generics
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1910892/what-is-the-difference-between-super-and-extends-in-java-generics">what is the difference between &#39;super&#39; and &#39;extends&#39; in Java Generics</a><br>
    <a href="https://stackoverflow.com/questions/5495383/java-generics-wildcard-question-list-extends-a">Java Generics WildCard Question: List&lt;? extends A&gt;</a>  </p>
  </blockquote>
  
  
  
  <p>I discovered a strange behaviour of Java generics that I can't explain to myself.</p>
  
  <p>If I try the following code, I would expect that it should work</p>
  
  <pre><code>List&lt;? extends Number&gt; list = new ArrayList&lt;&gt;();
  list.add(new Integer(2));
  list.add(new Float(2.0f));
  </code></pre>
  
  <p>But this leads to an compiler error.</p>
  
  <p>If I change the first line to</p>
  
  <pre><code>List&lt;? super Number&gt; list = new ArrayList&lt;&gt;();
  </code></pre>
  
  <p>it works fine for the compiler.</p>
  
  <p>Can anyone explain that to me?
  What is the difference between <strong>? extends</strong> and <strong>? super </strong>?</p>