反射之------获得运行时类的方法(非指定)
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); } } }
迎风少年
【推荐】100%开源!大型工业跨平台软件C++源码提供,建模,组态!
【推荐】2025 HarmonyOS 鸿蒙创新赛正式启动,百万大奖等你挑战
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
【推荐】开源 Linux 服务器运维管理面板 1Panel V2 版本正式发布
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步