准备调用的类
package ss;
public class Use {
public static Integer demo( String s ){
System.err.println(s+"<<<<<<成功!");
Integer ss=1;
return ss;
}
}
执行调用的类
public class Ceshi {
public static void main(String[] args) {
try {
String className = "ss.Use";
Class<?> testClass = Class.forName(className);
Method saddMethod2 = testClass.getMethod("demo", new Class[]{String.class});
String result=saddMethod2.invoke(null,new Object[]{"测试反射"}).toString();
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
}