package test.action;
import test.entity.City;
public class Test {
public static void main(String[] args) {
City c=new City("111","江苏","22");
show(City.class);
}
public static void show(Class c1){
try {
Class c =Class.forName(c1.getName());
c.getConstructors();
try {
City o=(City) c.newInstance();
//这里如果不采用上述强转,该怎么得到City对象呢?
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}