public class Person { public void sayHello() { System.out.println("Hello!"); } } Class<Person> personClass = Person.class; Method[] methods = personClass.getDeclaredMethods(); for (Method method : methods) { if (method.getName().equals("sayHello")) { method.invoke(person, null); } }


上一篇:
下一篇:
切换中文