Reputation: 31
I have a java meta annotation as such
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.ANNOTATION_TYPE })
public @interface Qualifier {
}
I then have another annotation:
@Qualifier
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE })
public @interface LeafEntity {
String name() default "";
}
At runtime I can extract the LeafEntity annotation using
getClass().getAnnotation(LeafEntity.class);
However, I would like to know if it is possible to access anything about the Qualifier? I mean what is the purpose of annotations on annotations if you can't access anything about them?
I have tried all of the following:
getClass().getAnnotation(Qualifier.class);
getClass().getAnnotation(LeafEntity.class).getClass().getAnnotation(Qualifier.class);
getClass().getAnnotation(LeafEntity.class) instanceof Qualifier.class;
If someone knows how to access the Qualifier annotation I would appreciate an example..
The reason this is important is that I have a base annotation called Qualifier. I would like to allow my users to define any annotation they like simply applying the Qualifier annotation to it. Then I would scan the class for any annotation that was annotated by the Qualifier annotation. But that's impossible if I can't access or identify Qualifier annotations.
Thanks in Advance.
Upvotes: 3
Views: 1319
Reputation: 36339
Couldn't you give Qualifier a value with a default? This way you'll be able to extract it.
public @interface Qualifier {
boolean value default true;
}
Upvotes: 1
Reputation: 53694
Did you try:
getClass().getAnnotation(LeafEntity.class).annotationType().getAnnotation(Qualifier.class);
Upvotes: 5