如何获取注释元素的默认值?

Jin*_*won 4 java reflection annotations

假设我有一个注释。

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MyAnnotation {
    int value() default 1;
}
Run Code Online (Sandbox Code Playgroud)

有什么方法可以获取1使用反射之类的价值吗?

Psh*_*emo 5

怎么样

MyAnnotation.class.getMethod("value").getDefaultValue()
Run Code Online (Sandbox Code Playgroud)