Get a list of all public methods, both declared and inherited in Java
Description
The following code shows how to get a list of all public methods, both declared and inherited.
Example
/*ww w.ja v a2 s . c o m*/
import java.lang.reflect.Method;
public class Main {
public static void main(String[] argv) throws Exception {
Class cls = java.lang.String.class;
Method[] methods = cls.getMethods();
for (int i = 0; i < methods.length; i++) {
Class returnType = methods[i].getReturnType();
Class[] paramTypes = methods[i].getParameterTypes();
System.out.println(methods[i]);
}
}
}
The code above generates the following result.