我刚比较过new ,clone,newInstance的性能
sun 1.4.1,win2000 pro,p4
结果发现在 重复100,000次
(单位毫秒)
construct cost 16
clone cost 78
reflect cost 62
而constuct 很稳定,其次是reflect,有少量波动31-67之间,clone最不稳定,50-250,创建的对象只是一个有int成员变量的类,而且clone也没有对它赋值。
我的结论:clone是sun的历史遗留特性,使用及其不方便。sun不会优化,所以不推荐使用
(doug lea 就一直主张自己写个duplicate)
reflect 1.4 之后优化了很多,需要灵活性时推荐使用。
最死板,最快的当然就是new了。