ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 获取空参成员方法 ~~~ Class c = Class.forName("User"); //获取的是class文件中所有的公共方法成员,包括继承的. //Method[] methods = c.getMethods(); Object o = c.newInstance(); //获取指定的方法名,第二个参数以后是需要传入的参数 Method show = c.getMethod("show"); show.invoke(o); ~~~ ## 获取有参成员方法并运行 ~~~ Class c = Class.forName("User"); //获取的是class文件中所有的公共方法成员,包括继承的. //Method[] methods = c.getMethods(); Object o = c.newInstance(); //获取指定的方法名,第二个参数以后是需要传入的参数 Method show = c.getMethod("show", String.class); show.invoke(o, "jack"); ~~~