方法覆盖的注释反思

时间:2015-05-07 20:27:56

标签: java reflection annotations

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

/* 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);

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

1 个答案:

答案 0 :(得分:2)

尝试使用Spring核心的AnnotationUtils类。

我认为您可以根据需要从父课程中获取注释。