title: Error when using Generic with Class<?> parameter
body: <p>Got some problem when using Generic with Enum:</p>
  
  <pre><code>enum MyEnum1 {
      // ...
      public static MyEnum fromString(String enumStr) { /* ... */ }
  }
  
  enum MyEnum2 {
      // ...
      public static MyEnum fromString(String enumStr) { /* ... */ }
  }
  
  enum MyEnum3 {
      // ...
      public static MyEnum fromString(String enumStr) { /* ... */ }
  }
  
  class MyClass {
      Map&lt;Class&lt;? extends Enum&lt;?&gt;, EnumSet&lt;? extends Enum&lt;?&gt;&gt;&gt; map;
  
      public &lt;E extends Enum&lt;E&gt;&gt; void addValue2EnumSet(Class&lt;E&gt; enumType, E value)；
  
      // enumType and valueStr is of the same length
      public static Map&lt;Class&lt;? extends Enum&lt;?&gt;, EnumSet&lt;? extends Enum&lt;?&gt;&gt;&gt; getMapOfEnumSet(Class&lt;? extends Enum&lt;?&gt;&gt;[] enumTypes, String[] valueStrs) {
          MyClass c = // ...
          for (int i = 0; i &lt; enumTypes.length; ++i) {
              // for each enumType and valueStr pair
              // add the value (= Enum1/2/3.fromString(valueStr)) to the Map
              Class&lt;? extends Enum&lt;?&gt;&gt; enumType = enumTypes[i];
              String valueStr = valueStrs[i];
              Method fromStringMethod = enumType.getDeclaredMethod("fromString", String.class);
  
              // error!
              c.addValue2EnumSet(enumType, enumType.cast(fromStringMethod.invoke(null, valueStr))); 
          }
          return c.map;
      }
  }
  </code></pre>
  
  <p>In this line <code>c.addValue2EnumSet(enumType, enumType(fromStringMethod.invoke(null, valueStr)));</code>, an compile-error is the second parameter, <code>Found: 'java.lang.Enum&lt;?&gt;</code>, required: '? extends java.lang.Enum'`</p>
  
  <p>How to call <code>addValue2EnumSet()</code> in <code>getEnumSetOf()</code>? </p>
  
  <p>In this case, a <code>Class&lt;? extends Enum&lt;?&gt; enumType</code> parameter is passed, and it is used to judge which kind of Enum (Enum1/2/3) is the target, then call the <code>fromString()</code> method to generate the corresponding Enum instance. I have no idea but the reflection to get methods from the enumType.</p>
  
  <p>The difficult is that the two parameters of <code>getEnumSetOf</code> are arrays, and each element in the first param, e.g., <code>enumTypes[0]</code>, choose the corresponding Enum Type of second param, e.g., <code>valueStrs[0]</code>. That is to say, the target type of <code>valueStrs[0]</code> is <code>enumTypes[0]</code>.</p>