package com.heima.userJSTL; import java.lang.reflect.Method; public class PersomTestMethod { public static void main(String[] args) { Class<Person> aClass = Person.class; Method[] methods = aClass.getMethods();//获取运行时类及其所有父类的所有被public修饰的方法 for (Method method : methods) { System.out.println(method); } System.out.println("==================="); Method[] declaredMethods = aClass.getDeclaredMethods();//getDeclaredMethods();获取当前运行时类的所有方法(不包括父类的方法) for (Method declaredMethod : declaredMethods) { System.out.println(declaredMethod); } } }
原文:https://www.cnblogs.com/ZYH-coder0927/p/13784461.html