title: Java Generic bound (constraint) for Enum
body: <p>I'm trying to bound (constrain) a Java generic type variable to be an enum (any enum) and failing. Might you be able to tell me why?</p>
  
  <pre><code>import org.supercsv.cellprocessor.ift.CellProcessor;
  import org.supercsv.cellprocessor.ift.StringCellProcessor;
  
  public class ParseEnum&lt;TEnum extends Enum&gt; extends CellProcessorAdaptor implements StringCellProcessor {
  
      public Object execute(final Object value, final CsvContext context) {
          ...
          final TEnum result;
          if (value instanceof TEnum) {
              result = (TEnum) value;
          } else if( value instanceof String ) {
                  result = TEnum.valueOf((String)value);
          } else {
              ...
          }
          ...
  }
  </code></pre>
  
  <p>(These are bits of my actual code attempting to extend a SuperCSV CellProcessor. )</p>
  
  <p><code>value instanceof TEnum</code> gives me this error (in Eclipse):</p>
  
  <blockquote>
    <p>"Cannot perform instanceof check against type parameter TEnum. Use its
    erasure Enum instead since further generic type information will be
    erased at runtime"</p>
  </blockquote>
  
  <p><code>TEnum.valueOf((String)value)</code> gives me this error:</p>
  
  <blockquote>
    <p>"The method valueOf(Class, String) in the type Enum is not
    applicable for the arguments (String)"</p>
  </blockquote>