This question already has an answer here:
I want get all content code of method (System.out.println("foo1");
and System.out.println("foo2");
in may case) but I do not find?
import java.lang.reflect.Method;
public class DisplayMethod {
public static void main(String[] args) {
final Method[] methods = DisplayMethod.class.getDeclaredMethods();
for (final Method method : methods) {
System.out.println(method.getName() + " " + method.toGenericString());
}
}
private void foo1() {
System.out.println("foo1");
}
private void foo2() {
System.out.println("foo2");
}
}
actual result:
main public static void sof.DisplayMethod.main(java.lang.String[])
foo1 private void sof.DisplayMethod.foo1()
foo2 private void sof.DisplayMethod.foo2()
target result:
foo1 private void sof.DisplayMethod.foo1() { System.out.println("foo1"); }
foo2 private void sof.DisplayMethod.foo2() { System.out.println("foo2"); }
Aucun commentaire:
Enregistrer un commentaire