List all declared methods in Java

Description

The following code shows how to list all declared methods.

Example


/*from   w  ww.j a  v a2  s  .c o  m*/
import java.lang.reflect.Method;

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 »
    Reflection »




Annotation
Array
Class
Constructor
Field
Generics
Interface
Method
Modifier
Package
Proxy