我有课
@ReadOnlyViewable(category = "Cache", description = "View the contents of a cache")
public class ReflectingCacheJmx<K, V> extends CacheJmx<K, V> {
我在上面添加了注释
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ReadOnlyViewable {
String description();
String category();
}
然后我有一个子类:
public class ObservableReflectingCacheJmx<K, V> extends ReflectingCacheJmx<K, V> {
以及其中的一个子类:
public class CounterpartyCacheJmx extends ObservableReflectingCacheJmx<CounterpartyKey, Counterparty> {
当我举一个例子
CounterpartyCacheJmx
和电话
getClass().getAnnotation(ReadOnlyViewable.class)
我得到的结果是
null
.
另一方面如果我打电话
getClass().getSuperclass().getSuperclass().getAnnotation(ReadOnlyViewable.class)
我把注释拿回来了。
我以为
getAnnotation
还应该在超类和
getDeclaredAnnotation
没有。
我的理解错了吗?我是否需要自己手动运行超类链(或使用第三方库这样做)才能找到此注释?
春天
ApplicationContext::getBeansWithAnnotation
在结果中返回这些bean
Map
因此,这似乎在对注释进行某种深度解析。