'java.lang.reflect.Method.getDefaultValue()'方法的实用程序?

Ser*_*gio 5 java reflection

在java.lang.reflect.Method类中,方法getDefaultValue()的目标是什么?有人能指出这种方法有用的情况吗?

方法API的描述对我说不多,我不知道是什么" annotation member represented by this Method instance":

返回此Method实例表示的注释成员的默认值.如果成员是基本类型,则返回相应包装类型的实例.如果没有与成员关联的默认值,或者方法实例不表示注释类型的声明成员,则返回null.

Gil*_*zan 11

注释有"属性"作为方法.例如:

public @interface Example {
    public String stringValue() default "string default value";
    public int intValue() default 10;
}
Run Code Online (Sandbox Code Playgroud)

getDefaultValue()从一个注释的方法返回以这种方式定义的注释"属性"的默认值.在该示例中,该方法的默认值stringValue()"string default value".

  • 我明白了,所以'Method.getDefaultValue()'只有在注释中声明方法时才有意义. (2认同)