我有一個Java元註解這樣的Java元註解在運行時
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.ANNOTATION_TYPE })
public @interface Qualifier {
}
然後我還有一個註釋:
@Qualifier
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE })
public @interface LeafEntity {
String name() default "";
}
在運行時,我可以提取使用
getClass().getAnnotation(LeafEntity.class);
的LeafEntity註釋
不過,我想知道是否有可能訪問有關限定符什麼?我的意思是,如果您無法訪問註釋,註釋的目的是什麼?
我已經嘗試了所有的以下內容:
getClass().getAnnotation(Qualifier.class);
getClass().getAnnotation(LeafEntity.class).getClass().getAnnotation(Qualifier.class);
getClass().getAnnotation(LeafEntity.class) instanceof Qualifier.class;
如果有人知道如何訪問限定符註解我將不勝感激的例子..
的原因,這是很重要的是,我有一個基地註釋稱爲Qualifier。我希望允許我的用戶定義他們喜歡的任何註釋,只需將Qualifier註釋應用到它。然後,我將掃描該類以查找由Qualifier批註註釋的任何批註。但是如果我無法訪問或識別Qualifier註釋,這是不可能的。
在此先感謝。
是的,這是票。謝謝。 – user620165 2011-04-12 10:27:33