title: How to cast java.lang.reflect.Type to enum?
body: <p>I have fairly simple problem.<br>
  I have a variable of type java.lang.reflect.Type and I want to do two different things to it in case its holds class or enumeration. I can fairly simple check if the varaible is enum by simply asking <code>.isEnum()</code>. However to call the specific enumeration methods I need to cast this variable to be enumeration. Here is some code for illustration. I know it does not make much of a sence, but its just for the cast illustration:</p>
  
  <pre><code>public class TestClass {
      public static String text = "MySampleTextClass.";
  }
  public enum TestEnum {
      MySampleText
  }
  public class Tester {
      public static Object retrieveValue (java.lang.reflect.Type myVar, String enumStringValue) {
          String enumStringValue = "MySampleText";
  
          // the variable is enum!!!
          if (myVar.isEnum()) {
              return (Enum myVar).valueOf(enumStringValue);
          }
          // the variable is class!!!
          else {
              return myVar.getClass().getSimpleName();
          }
      }
  }
  </code></pre>
  
  <p>I tried casts like </p>
  
  <pre><code>(java.lang.Enum myVar).valueOf(enumString);
  </code></pre>
  
  <p>or </p>
  
  <pre><code>(java.lang.Enum&lt;?&gt; myVar).valueOf(enumString); 
  </code></pre>
  
  <p>but I can't make it work.</p>
  
  <p>Any ideas?</p>