Cloneable is a marker interface. It does not contain methods.
The fact is that the clone method is defined in the Object class. Since all classes implement the Object class, this means that all classes have a clone method. However, not all objects actually support it. Some of them just throw a CloneNotSupportedException . But this clone method is a native method, and for the exact behavior of this method is not displayed in the java source code. Thus, he lacks transparency.
The Cloneable will help us understand which classes are actually cloned and which are not. By convention, classes that do not implement Cloneable will throw a CloneNotSupportedException .
Note. The clone method is also marked protected . That way, he also agrees to override it to make it public in supporting classes.
The clone design was introduced in JDK1. These days, the general consensus is that the java clone design contains some flaws. Some people prefer to simply create a clone constructor (for example, public Color(Color toCopy) {this.color = toCopy.color;} )
source share