通过字节码获取到的方法


1.
Method[] methods = Yuitest.class.getMethods();
for (Method method:methods){
System.out.println( method.getName());
}
2.
Yuitest yuitest =new Yuitest();
Method[] methods = yuitest.getClass().getMethods();
for (Method method:methods){
System.out.println( method.getName());
}
3.
方法:
public String goodName(String name) {
    System.out.println("哈哈哈。。。。。。。。。。。。");
return "aaa";
}

加载获取:
Class<User> aClass = (Class<User>) Class.forName("com.example.demo.user.entity.User");
Method method = aClass.getMethod("goodName", String.class);
User user = aClass.newInstance();
Object aa = method.invoke(user, "aa");
System.out.println(aa);
静态获取:
public static String goodName(String... args) {
System.out.println("哈哈哈。。。。。。。。。。。。");
for (String str:args){
System.out.println(str);
}
return "aaa";
}
获取:
Method goodName = User.class.getMethod("goodName", String[].class);
goodName.invoke(null,new Object[]{new String[]{"1","2"}});


原文地址:https://www.cnblogs.com/shanshen/p/9821216.html