public class UserName {
protected void getMethod(String name) {
System.out.println(name + "成功獲得method");
}
}
String classname1 = "com.meicai.test.prototype.UserName";
Class c1 = Class.forName(classname1);
Object object = c1.newInstance();
Method method = c1.getDeclaredMethod("getMethod", String.class);
method.setAccessible(true);
method.invoke(object, "張三");
執行結果
張三成功獲得method