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.  ja va  2  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.





















Home »
  Java Tutorial »
    java.lang.reflect »




Array
Constructor
Field
Method
Modifier
ParameterizedType
TypeVariable