I am not fully understanding the idea of returning super.clone() in the clone() method of a class. First of all, wouldn’t that relate to it returning an object that is a superclass which contains LESS data than requested, because a superclass “is not a” subclass, but a subclass “is a” superclass. And if there were a long chain of subclasses, each calling super.clone(), why wouldn’t that lead to it eventually calling Object.clone() at the root of the chain, which isn’t any of the subclasses?
Sorry if that was confusing; I confuse myself sometimes
The implementation of
clone()inObjectchecks if the actual class implementsCloneable, and creates an instance of that actual class.So if you want to make your class cloneable, you have to implement
Cloneableand downcast the result ofsuper.clone()to your class. Another burden is that the call tosuper.clone()can throw aCloneNotSupportedExceptionthat you have to catch, even though you know it won’t happen (since your class implementsCloneable).The
Cloneableinterface and theclonemethod on theObjectclass are an obvious case of object-oriented design gone wrong.