Java Reflection - Java Method.getName()








Syntax

Method.getName() has the following syntax.

public String getName()

Example

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

import java.lang.reflect.Method;
/*  w  ww  .j av  a2 s  . c  o m*/
public class Main {

  public static void main(String[] args) {
    Class aClass = String.class;

    // Get the methods
    Method[] methods = aClass.getDeclaredMethods();

    // Loop through the methods and print out their names
    for (Method method : methods) {
      System.out.println(method.getName());
    }
  }
}

The code above generates the following result.