title: Method parameter annotations access
body: <p>It took me a while to figure out that I was not making a mistake in annotating my method parameters.
  <br>
  But I am still not sure why, in the following code example, the way no. 1 does not work:</p>
  
  <pre><code>import java.lang.annotation.Annotation;
  import java.lang.annotation.Retention;
  import java.lang.annotation.RetentionPolicy;
  import java.lang.reflect.Method;
  
  public class AnnotationTest {
  
      @Retention(RetentionPolicy.RUNTIME)
      @interface MyAnnotation {
          String name() default "";
          }
  
      public void myMethod(@MyAnnotation(name = "test") String st) {
  
      }
  
      public static void main(String[] args) throws NoSuchMethodException, SecurityException {
          Class&lt;AnnotationTest&gt; clazz = AnnotationTest.class;
          Method method = clazz.getMethod("myMethod", String.class);
  
          /* Way no. 1 does not work*/
          Class&lt;?&gt; c1 = method.getParameterTypes()[0];
          MyAnnotation myAnnotation = c1.getAnnotation(MyAnnotation.class);
          System.out.println("1) " + method.getName() + ":" + myAnnotation);
  
          /* Way no. 2 works */
          Annotation[][] paramAnnotations = method.getParameterAnnotations();
          System.out.println("2) " + method.getName() + ":" + paramAnnotations[0][0]);
      }
  
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>    1) myMethod:null
      2) myMethod:@AnnotationTest$MyAnnotation(name=test)
  </code></pre>
  
  <p>Is it just a flaw in the annotation imnplementation in Java?
  Or is there a logical reason why the class array returned by <code>Method.getParameterTypes()</code> does not hold the parameter annotations?</p>