Why wasn't the .clone()
method specified in the java.lang.Cloneable
interface ?
Basically, it's a broken interface. Ken Arnold and Bill Venners discussed it in Java Design Issues.
Arnold:
If I were to be God at this point, and many people are probably glad I am not, I would say deprecate
Cloneable
and have aCopyable
, becauseCloneable
has problems. Besides the fact that it's misspelled,Cloneable
doesn't contain theclone
method. That means you can't test if something is an instance ofCloneable
, cast it toCloneable
, and invokeclone
. You have to use reflection again, which is awful. That is only one problem, but one I'd certainly solve.