如何获取被重写方法的注释对象。
/* 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
时来自父类的注释实例指的是 child 的方法?
最佳答案
尝试使用AnnotationUtils
来自 Spring 核心的类。
我认为您会根据需要从父级的类中获取注释。
关于java - 重写方法的注释反射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30111052/