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

时间:2012-09-14 20:25:10

标签: java reflection

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

方法API的描述对我说不多,我没有得到“annotation member represented by this Method instance”:

  

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

1 个答案:

答案 0 :(得分:11)

注释将“属性”作为方法。例如:

public @interface Example {
    public String stringValue() default "string default value";
    public int intValue() default 10;
}

注释中Method的getDefaultValue()返回以这种方式定义的注释“attribute”的默认值。在示例中,方法stringValue()的默认值为"string default value"

相关问题