2006年12月26日
使用new是不是编译期就加载类到内存中?

为什么设计类时一般不推荐使用new,而推荐使用运行期再加载类的方式(Class.forName),比如Spring框

架就完全不用new。

Spring中,使用以下方式获得bean的引用:
ApplicationContext ctx=new FileSystemXmlApplicationContext("bean.xml");
Action action = (Action) ctx.getBean("TheAction");

其中getBean()函数的主要作用是否是加载类,并返回对象的引用?它的主要代码是否为以下代码呢?:
Class c=Class.forName("TheAction");
Object o=c.newInstance();
return o;

有待查看Spring的源代码验证自己的猜测!!!