方法的注释反射被覆盖

Annotation Reflection for Method overrided

如何获取被覆盖的方法的注释对象。

/* I created a custom annotation named AclIgnore, 
   and I have the next following piece of code: */

public class abstract Parent{
    @AclIgnore
    public abstract String getName();

}

public class Children extends Parent{
    @Override
    public String getName(){
          return "theChildren";
   }
}

   /*I want the AclIgnore of Parent.getName() but the next code returns null */
/*method is getName of the instance*/
AclIgnore aclIgnore = method.getAnnotation(AclIgnore.class);

我的问题是:当我有一个引用子方法的 java.lang.reflect.Method 实例时,是否可以从父 class 获取 AclIgnore 注释?

尝试使用 Spring 核心中的 AnnotationUtils class。

我认为您会根据需要从 parent 的 class 中获得注释。