java - 重写方法的注释反射

标签 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 时来自父类的注释实例指的是 child 的方法?

最佳答案

尝试使用AnnotationUtils来自 Spring 核心的类。

我认为您会根据需要从父级的类中获取注释。

关于java - 重写方法的注释反射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30111052/

相关文章:

go - 在 Go 中查找结构的底层匿名字段类型

C# 反射从类型中获取对象

ios - 如何在 Split View ipad 编程中实时在 MKMap 上添加引脚注释

Java:同步操作与波动性究竟有何关系?

java - 在 Eclipse 中从 Java 访问 Scala 实例变量

Swift - 可以以编程方式知道函数是 @IBAction 还是框架名称?

java - 获取java项目中带有特定注解的所有类

java - _version、_id 等的 spring-data-elasticsearch 元数据注释

java - 如何在抽屉导航中提供 SettingsActivity?

java - 对象中对象的反序列化抛出 ClassNotFoundException