import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Hello {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
ClassLoader load=ClassLoader.getSystemClassLoader();
try {
Class<Test> c=(Class<Test>) load.loadClass("Test");
Method m=c.getMethod("print", String.class);
m.invoke(c.newInstance(), "ss");
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
import java.lang.reflect.Method;
public class Hello {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
ClassLoader load=ClassLoader.getSystemClassLoader();
try {
Class<Test> c=(Class<Test>) load.loadClass("Test");
Method m=c.getMethod("print", String.class);
m.invoke(c.newInstance(), "ss");
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public class Test {
public void print(String str){
System.out.println(str+":这是一个测试程序");
}
}