title: Java generics: put() on Map<String,capture#3-of ? extends AbstractClass> is not applicable for the arguments (String, AbstractClass)
body: <p>I'm trying to implement a sort of intern factory for multiple classes that extend from a common parent. Much of the logic is identical, but it can't really be inherited because the lookups need to be static. The desired syntax is something like:</p>
  
  <pre><code>Car c = AbstractClass.valueOf(Car.class, "Ford");
  </code></pre>
  
  <p>with Car having specific methods related to cars, but the instances are stored in a common cache. Here's what I have so far. My compile error is on the put in the constructor:</p>
  
  <p>"The method put(String, capture#3-of ? extends AbstractClass) in the type Map is not applicable for the arguments (String, AbstractClass)"</p>
  
  <pre><code>import java.util.Collection;
  import java.util.HashMap;
  import java.util.LinkedHashMap;
  import java.util.Map;
  import java.util.Set;
  import java.util.TreeSet;
  
  public abstract class AbstractClass {
  
      private static Map&lt;Class&lt;? extends AbstractClass&gt;, LinkedHashMap&lt;String, ? extends AbstractClass&gt;&gt; map = new HashMap&lt;Class&lt;? extends AbstractClass&gt;, LinkedHashMap&lt;String, ? extends AbstractClass&gt;&gt;();
  
      private static synchronized &lt;T extends AbstractClass&gt; Map&lt;String, T&gt; getNameMap(Class&lt;T&gt; clazz) {
          LinkedHashMap&lt;String, T&gt; nameToEnum = (LinkedHashMap&lt;String, T&gt;) map.get(clazz);
          if (nameToEnum == null) {
              nameToEnum = new LinkedHashMap&lt;String, T&gt;();
              map.put(clazz, nameToEnum);
          }
  
          return nameToEnum;
      }
  
      public static &lt;T extends AbstractClass&gt; T valueOf(Class&lt;T&gt; clazz, String name) {
          return getNameMap(clazz).get(name);
      }
  
      public static &lt;T extends AbstractClass&gt; Collection&lt;T&gt; VALUES(Class&lt;T&gt; clazz) {
          return getNameMap(clazz).values();
      }
  
      public static &lt;T extends AbstractClass&gt; Set&lt;T&gt; SORTED_VALUES(Class&lt;T&gt; clazz) {
          return new TreeSet&lt;T&gt;(getNameMap(clazz).values());
      }
  
      AbstractClass(String name) {
          AbstractClass.getNameMap(this.getClass()).put(name, this);
      }
  
  }
  </code></pre>