北京尚学堂 - 工厂系列 - 第三讲 中讲解了
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
Properties props = new Properties();try {
props.load(Test.class.getClassLoader().getResourceAsStream("spring.properties"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String vehicleTypeName = props.getProperty("vehicleType");
System.out.println(vehicleTypeName);
Object o = Class.forName(vehicleTypeName).newInstance();
Moveable m = (Moveable) o;
m.run();
}