vendredi 29 mai 2015

Java googlecode reflections - seek a method with specific annotation and its annotation element

Suppose I have this annotation class

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MethodXY {
    public int x();
    public int y();
}

public class AnnotationTest {
    @MethodXY(x=5, y=5)
    public void myMethodA(){ ... }

    @MethodXY(x=3, y=2)
    public void myMethodB(){ ... }
}

So is there a way to look into an object, "seek" out the method with the @MethodXY annotation, where its element x = 3, y = 2, and invoke it?

This question is already answered here using core Java Reflection. I want to know if this can be done using Reflections 0.9.9-RC1 API without having to iterate over methods using some for loop code.





Aucun commentaire:

Enregistrer un commentaire