[jdom-interest] A factory for clone ??

Joseph Bowbeer jozart at csi.com
Wed Sep 5 15:46:27 PDT 2001

Paul Libbrecht writes:

> Just came accross a delicacy... when cloning, you'd really
> love that the proper subclasses I am making are cloned as
> well...  is this sufficient to override the clone method of the
> given subclasses ?

I'm not sure what you mean by "is this sufficient".  The recommended
practice, if you override the clone method in a nonfinal class, is to return
an object obtained by invoking super.clone.

This tidbit is from Item 10, Chapter 3 in Josh Bloch's Effective Java
Programming Guide.


 "If all of a class's superclasses obey this rule, then invoking super.clone
will eventually invoke Object's clone method, creating an instance of the
right class. This mechanism is vaguely similar to automatic constructor
chaining, except that it isn't enforced."

Joe Bowbeer

More information about the jdom-interest mailing list