- 1
- try {
- 2 //动态加载类,在运行时刻进行加载,编译不会报任何错误
- 3 Class c1 = Class.forName(args[0]);
- 4 //通过类类型来创建类的对象--我想要加载的类必须都符合一个标准,也就是说要实现统一的接口
- 5 OfficeAble officeAble = (OfficeAble) c1.newInstance();
- 6
- } catch(ClassNotFoundException e) {
- 7 // TODO Auto-generated catch block
- 8 e.printStackTrace();
- 9
- }
来源: http://www.bubuko.com/infodetail-1969512.html