Java 'Prototype' pattern - new vs clone vs class.newInstance
- by Guillaume
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 ?