title: Why is Class.getAnnotation() requiring me to do a cast?
body: <p>I'm using Java 1.6.0_25.</p>
  
  <p>I have an annotation defined:</p>
  
  <pre><code>@Target(ElementType.TYPE)
  @Retention(RetentionPolicy.RUNTIME)
  public @interface Resource {
      String value();
  }
  </code></pre>
  
  <p>And later when I use getAnnotation:</p>
  
  <pre><code>Resource resource = (Resource)cls.getAnnotation(Resource.class);
  </code></pre>
  
  <p>the compiler and IDE agree that I must cast the result, but getAnnotation is declared in the Java 1.5 documentation as:</p>
  
  <pre><code>public &lt;A extends Annotation&gt; A getAnnotation(Class&lt;A&gt; annotationClass);
  </code></pre>
  
  <p>Since Resource.class is of type Class, it seems to me that this means that cls.getAnnotation(Resource.class) should return type Resource, and I should need to cast.</p>
  
  <p>All examples I've found using getAnnotation don't have a cast, so I must be doing something wrong.</p>