Outer loop
for (Annotation[] annotations : paramAnnotations) { ... }
must use an explicit counter, otherwise you do not know which parameter you are processing right now
final Annotation[][] paramAnnotations = method.getParameterAnnotations(); final Class[] paramTypes = method.getParameterTypes(); for (int i = 0; i < paramAnnotations.length; i++) { for (Annotation a: paramAnnotations[i]) { if (a instanceof Foo) { System.out.println(String.format("parameter %d with type %s is annotated with @Foo", i, paramTypes[i]); } } }
Also make sure your annotation type is annotated with @Retention(RetentionPolicy.RUNTIME)
From your question it is not clear what you are trying to do. We agree with the difference of formal parameters with the actual arguments:
void foo(int x) { } { foo(3); }
where x is the parameter and 3 is the argument?
It is not possible to get method arguments through reflection. If at all possible, you will have to use the sun.unsafe package. I can not tell you about this.
Cephalopod
source share