@Test
public void test5() throws Exception {
String classPath = "java.util.Date";
Object instance = getInstance(classPath);
System.out.println("对象1:"+instance);
classPath = "com.reflex.Person";
Object instance1 = getInstance(classPath);
System.out.println("对象2:"+instance1);
}
public Object getInstance(String classPath) throws Exception {
Class clazz = Class.forName(classPath);
return clazz.newInstance();
}
运行结果:
对象1:Tue May 03 21:58:54 CST 2022
对象2:Person{name='null', age=0}



