vendredi 3 novembre 2017

Java how to get value of a method with an custom annotation by reflection [duplicate]

I need to get the returned value of any method annotated with an specific enum in a class using Reflection. How can I accomplish that?

I know that a have to create a custom annotation that receive a Type as parameter, but I don't know what else I have to do.

ex.:

enum Type{ TYPE1, TYPE2, TYPE3}

public class MyClass{

@MyCustomAnnotation(type=Type.TYPE1)
public int myMethod1(){return 1;}

@MyCustomAnnotation(type=Type.TYPE2)
public int myMethod2(){return 2;}

}





Aucun commentaire:

Enregistrer un commentaire