Class clazz =Class.forName("com.test.Service");
Object o =clazz.newInstance();
User user =new User();
user.setUsername("zhangsan");
Method method =clazz.getMethod("f",null);
method.invoke(o,new Object[]{user});
报错:
java.lang.NoSuchMethodException: com.test.Service.f()
at java.lang.Class.getMethod(Class.java:978)
at com.test.Test.main(Test.java:10)