title: Using Java Generics with HashMap
body: <p>I have a class B and C which both extends class A:</p>
  
  <pre><code>public class B extends A {...}
  public class C extends A {...}
  </code></pre>
  
  <p>How can I use Java generics with a HashMap this way?</p>
  
  <pre><code>B b = new B();
  C c = new C();
  
  Map&lt;String, ? extends A&gt; map = new HashMap&lt;String, A&gt;();
  
  map.put("B", b);
  map.put("C", c);
  </code></pre>
  
  <p>Eclipse always shows an error:</p>
  
  <blockquote>
    <p>The method put(String, capture#1-of ? extends A) in the type
    Map is not applicable for the
    arguments (String, B)</p>
  </blockquote>
  
  <p>and </p>
  
  <blockquote>
    <p>The method put(String, capture#1-of ? extends A) in the type
    Map is not applicable for the
    arguments (String, C)</p>
  </blockquote>