运行时的Java元注释

use*_*165 3 java annotations

我有一个java元注释

@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.ANNOTATION_TYPE })
public @interface Qualifier {
}
Run Code Online (Sandbox Code Playgroud)

然后我有另一个注释:

@Qualifier
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE })
public @interface LeafEntity {
   String name() default "";
}
Run Code Online (Sandbox Code Playgroud)

在运行时,我可以使用提取LeafEntity注释

getClass().getAnnotation(LeafEntity.class);
Run Code Online (Sandbox Code Playgroud)

但是,我想知道是否可以访问有关限定符的任何内容?我的意思是如果您无法访问有关它们的任何内容,注释的注释目的是什么?

我尝试了以下所有方法:

getClass().getAnnotation(Qualifier.class);
getClass().getAnnotation(LeafEntity.class).getClass().getAnnotation(Qualifier.class);
getClass().getAnnotation(LeafEntity.class) instanceof Qualifier.class;
Run Code Online (Sandbox Code Playgroud)

如果有人知道如何访问限定符注释我会很感激一个例子..

这很重要的原因是我有一个名为Qualifier的基本注释.我想允许我的用户定义他们喜欢的任何注释,只需将Qualifier注释应用于它.然后我将扫描该类以查找由限定符注释注释的任何注释.但如果我无法访问或识别限定符注释,那是不可能的.

提前致谢.

jta*_*orn 5

你试过了吗:

getClass().getAnnotation(LeafEntity.class).annotationType().getAnnotation(Qualifier.class);
Run Code Online (Sandbox Code Playgroud)