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

前端 未结 6 985
别那么骄傲
别那么骄傲 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

    Gee. That's one of the worst idea I've ever heard.

    Don't do weird things. Even if you have measured and see some apparent improvement (well, zero chance of that in this case), think a long time before doing it.. Who knows it will be fixed in the next JVM. Then you are left with some weird piece of code that performs worse, is difficult to read, and some bugs because of that.

    I mean, it's not like people developing the JVM are idiots! Use new!

    I think you should get rid of that strange piece of code.

提交回复
热议问题