title: Java Enums: de-serializing an arbitrary enum from a file
body: <p>A co-worker ran into an interesting issue today, and while I think the actual, big-picture answer is "the fact that we're having this problem means we're doing something wrong", I figured I'd ask this anyway.</p>
  
  <p>Given the following:</p>
  
  <pre><code>public class CrazyEnumTest {
  
    public class EnumeratedThing&lt;T extends Enum&lt;T&gt;&gt; {
      public T myValue;
  
      public EnumeratedThing(T value) {
        myValue = value;
      }
    }
  
    public static void main (String[] args) {
      String className = args[0];
      String enumValue = args[1];
  
      Enum&lt;?&gt; value1 = Enum.valueOf(Class.forName(className), enumValue);
      EnumeratedThing&lt;?&gt; thing1 = new EnumeratedThing(value1);
    }
  }
  </code></pre>
  
  <p>I get the following compile error on the call to Enum.valueOf:</p>
  
  <p><code>Bound mismatch: The generic method valueOf(Class&lt;T&gt;, String) of type Enum&lt;E&gt; is not applicable for the arguments (Class&lt;capture#1-of ?&gt;, String). The inferred type capture#1-of ? is not a valid substitute for the bounded parameter &lt;T extends Enum&lt;T&gt;&gt;</code> </p>
  
  <p>So, my question is: is it possible to, given only the String representation of a enumerated type name as well as the .name() of one of its values, get a reference to the corresponding enumerated type object as an Enum?</p>