title: Handle TypeMirror and Class gracefully
body: <p>I'm just getting into javax AnnotationProcessing over here, and have run into an ugly case.  I'll illustrate it in a series of pseudo-code lines that describe my learning process:</p>
  
  <pre><code>MyAnnotation ann = elementIfound.getAnnotation(MyAnnotation.class);
  // Class&lt;?&gt; clazz = ann.getCustomClass();  // Can throw MirroredTypeException!
  // Classes within the compilation unit don't exist in this form at compile time!
  
  // Search web and find this alternative...
  
  // Inspect all AnnotationMirrors
  for (AnnotationMirror mirror : element.getAnnotationMirrors()) {
    if (mirror.getAnnotationType().toString().equals(annotationType.getName())) {
      // Inspect all methods on the Annotation class
      for (Entry&lt;? extends ExecutableElement,? extends AnnotationValue&gt; entry : mirror.getElementValues().entrySet()) {
        if (entry.getKey().getSimpleName().toString().equals(paramName)) {
          return (TypeMirror) entry.getValue();
        }
      }
      return null;
    }
  }
  return null;
  </code></pre>
  
  <p>The problem is that now I'm finding out that if the client code contains a core class like <code>java.lang.String</code> or <code>java.lang.Object</code> as a <code>Class</code> parameter, this line:</p>
  
  <pre><code>return (TypeMirror) entry.getValue();
  </code></pre>
  
  <p>...results in a <code>ClassCastException</code>, because the AnnotationProcessor environment is kind enough to actually retrieve the <code>Class</code> object in this case.</p>
  
  <p>I've figured out how to do everything I need to do with <code>TypeMirror</code> in the absence of <code>Class</code> - do I need to handle both of them in my code now?  Is there a way to obtain a <code>TypeMirror</code> from a <code>Class</code> object?  Because I can't find one</p>