title: Generic Enums in Java
body: <p>I have a basic Configuration class that provides all its possible keys and the type of the corresponding value types in an enum like so:</p>
  
  <pre><code>public class Configuration {
      public static enum Key {
          FIRST_KEY("actual key 1", Long.class),
          ANOTHER_KEY("actual key 2", Integer.class)
  
          public final String value;
          public final Class type;
  
          Key(String value, Class type) {
              this.value = value;
              this.type = type;
          }
      }
  }
  </code></pre>
  
  <p>What I would like to do is write a method that parses the value of a given key from a String and returns the value as the appropriate type. Basically this:</p>
  
  <pre><code>public &lt;T&gt; T getValue(Key&lt;T&gt; key, String valueStr);
  </code></pre>
  
  <p>This attempt fails at the method declaration already, since its appears that Enums in Java can not have type arguments. Any ideas on how to achieve something similar to this?</p>