Get specific method information by parameters in Java

Description

The following code shows how to get specific method information by parameters.

Example


/*from  www.j  a  v  a2s  .  c  o  m*/
import java.lang.reflect.Method;
public class Main {
  public static void main(final String[] args) {
    final Method byteValueMeth;
    final Method waitMeth;
    final Method waitDetailMeth;

    try {
      byteValueMeth = Number.class.getMethod("byteValue", null);
      waitMeth = Number.class.getMethod("wait", new Class[] {});
      waitDetailMeth = Number.class.getMethod("wait", new Class[] { long.class, int.class });
    } catch (final NoSuchMethodException ex) {
      throw new RuntimeException(ex);
    }

    System.out.println("byteValueMeth = " + byteValueMeth.toString());
    System.out.println("waitMeth = " + waitMeth.toString());
    System.out.println("waitDetailMeth = " + waitDetailMeth.toString());
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Reflection »




Annotation
Array
Class
Constructor
Field
Generics
Interface
Method
Modifier
Package
Proxy