Java Method.getDefaultValue()

Syntax

Method.getDefaultValue() has the following syntax.

public Object getDefaultValue()

Example

In the following code shows how to use Method.getDefaultValue() method.


/* www . jav a  2s.  c om*/
import java.lang.reflect.Method;

class X {
  public void objectMethod(String arg) {
    System.out.println("Instance method: " + arg);
  }

  public static void classMethod() {
    System.out.println("Class method");
  }
}

public class Main {
  public static void main(String[] args) {
    try {
      Class<?> clazz = Class.forName("X");
      X x = (X) clazz.newInstance();
      Class[] argTypes = { String.class };
      Method method = clazz.getMethod("objectMethod", argTypes);
      
      System.out.println(method.getDefaultValue()); 

    } catch (Exception e) {
      System.err.println(e);
    }
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang.reflect »




Array
Constructor
Field
Method
Modifier
ParameterizedType
TypeVariable