Java 'Prototype' pattern - new vs clone vs class.newInstance
Posted
by Guillaume
on Stack Overflow
See other posts from Stack Overflow
or by Guillaume
Published on 2010-03-11T17:46:43Z
Indexed on
2010/03/11
17:49 UTC
Read the original article
Hit count: 381
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 provides better performance than calling 'new' operator.
Using google to get some clues about that, I've found nothing really relevant about that. Here is a small excerpt found in a javdoc from an unknown project javdoc from an unknown project
Sadly, clone() is rather slower than calling new. However it is a lot faster than calling java.lang.Class.newInstance(), and somewhat faster than rolling our own "cloner" method.
For me it's looking like an old best practice of the java 1.1 time. Does someone know more about this ? Is this a good practice to use that with 'modern' jvm ?
© Stack Overflow or respective owner