提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
获取所有方法,包括超类
/**来自 时代Java公众号**/ //package com.nowjava; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] argv) throws Exception { Class clazz = String.class; System.out.println(getAllMethodsIncludeSuperClass(clazz)); } public static List<Method> getAllMethodsIncludeSuperClass( final Class<?> clazz) { List<Method> lf = new ArrayList<Method>(); for (Class<?> superClass = clazz; superClass != null && superClass != Object.class; superClass = superClass .getSuperclass()) { Method[] f = superClass.getDeclaredMethods(); /** * N o w J a v a .