【问题标题】:is it possible to get annotated method parameter? [duplicate]是否可以获得带注释的方法参数? [复制]
【发布时间】:2018-03-01 11:35:21
【问题描述】:

目前我正在处理自定义注释,我正在尝试捕获声明的带注释的方法参数值,例如:

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface CustomAnnotation {

}

public class CustomAnnotationTest {

  @CustomAnnotation
  public void annotationTest(String address){
    System.out.println("address :" + address);
  }
}

在这里我如何阅读这个 annotationTest 方法参数值“地址”使用

@customAnnotation.

谢谢。

【问题讨论】:

标签: java


【解决方案1】:

可以从Method获取注解

 CustomAnnotation customAnnotation = CustomAnnotationTest.class
         .getDeclaredMethod("annotationTest", String.class)
         .getAnnotation(CustomAnnotation.class);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-21
    • 2012-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多