String clasName = "org.test.a";
String method = "testA";
怎样实例化 className 并执行 method 方法
如果 method 对应方法有 参数,有返回,要怎样执行
------解决方案--------------------
- Java code
import java.lang.reflect.Method;public class StubTest { public static void main(String[] args) throws Exception{ Class<?> clazz= Class.forName("com.nbinfo.test.StubTest"); Object ob = clazz.newInstance(); Method method = clazz.getMethod("showMsg", String.class); method.invoke(ob, "HelloWorld"); } public void showMsg(String msg){ System.out.println(msg); }}