这个也没有解决说如果excel没有这个类还能运行啊
public class test { public static void main(String[] args) { // TODO Auto-generated method stub if("word".equals(args[0])){ Class c; try { c = Class.forName(args[0]); word w=(word)c.newInstance(); w.start(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if("excel".equals(args[0])){ Class c; try { c = Class.forName(args[0]); excel e=(excel)c.newInstance(); e.start(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
如果我没有excel的类,在编译时还是会报错,并不能实现这个功能,
难道说只能用接口,那样只能体现接口的作用