The implementation of clone()
in Object
checks if the actual class implements Cloneable
, and creates an instance of that actual class.
So if you want to make your class cloneable, you have to implement Cloneable
and downcast the result of super.clone()
to your class. Another burden is that the call to super.clone()
can throw a CloneNotSupportedException
that you have to catch, even though you know it won’t happen (since your class implements Cloneable
).
The Cloneable
interface and the clone
method on the Object
class are an obvious case of object-oriented design gone wrong.