Java 'Prototype' pattern - new vs clone vs class.newInstance

前端 未结 6 990
别那么骄傲
别那么骄傲 2021-02-08 18:11

In my project there are some \'Prototype\' factories that create instances by cloning a final private instance.

The author of those factories says that this pattern prov

6条回答
  •  时光说笑
    2021-02-08 18:33

    Absolutely, this type of practice is completely obsolete. The Java virtual machine has improved drastically since then. Object creation is extremely cheap. Another related practice, Object Pooling, is also obsolete because the cost of Object creation and cleanup is so much more efficient now. For some cases it might be useful (Jon Skeet gives some good examples here), but in no way should it be part of a base framework library such as this.

    I would suggest finding some new libraries and/or a new project to work on ;-)

    Check out this class article Java Urban Performance Legends for some more insight.

提交回复
热议问题