SE450: Clone: clone() [6/32] Previous pageContentsNext page

The intent is that

x.clone() != x

x.clone().getClass() == x.getClass()

x.clone().equals(x)

The last intent is not a requirement, but is generally true.

By convention, you obtain the returned object by calling super.clone(). If all superclasses do this, then x.clone().getClass() == x.getClass() will be true.

Object doesn't implement Cloneable itself. (Object.clone is protected.)

The Cloneable interface is meant to be a mixin interface, however it doesn't do a very good job of this.

Parts of Java that support cloning:

You can:

Previous pageContentsNext page