Get methods from a class in Java

Description

The following code shows how to get methods from a class.

Example


//www . j a v a  2  s  . c  o  m
import java.lang.reflect.Method;

public class Main {
  public static void main(final String[] args) {
    Method[] methods = String.class.getMethods();
    for (int idx = 0; idx < methods.length; idx++) {
      System.out.println(methods[idx] + " declared by " 
         + methods[idx].getDeclaringClass());
    }
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Reflection »




Annotation
Array
Class
Constructor
Field
Generics
Interface
Method
Modifier
Package
Proxy