lundi 22 mai 2017

Receive annotation value from annotated field

Is it possible to receive annotation value inside a field, that was annotated? Imagine that I have this interface:

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
    String value();
}

And I have such implementation:

class SomeClass {
    @MyAnnotation("Annotation")
    private MyClass myClass;
}

What I want to understand is: is it possible to receive value of MyAnnotation inside MyClass? I want to implement a method inside class MyClass, which will return a value of assigned annotation. So, that myClass.getAssignedAnnotationValue() will return "Annotation". If it is not possible, please inform me.





Aucun commentaire:

Enregistrer un commentaire