June 2018
Beginner
722 pages
18h 47m
English
The clone() method of the java.lang.Object class looks like this:
protected Object clone(){ //creates copy of the object}
The default result of this method returns a copy of the object fields as-is, which is fine if the values are not an object reference. Such values are called primitive type, which we will define precisely in Chapter 5, Java Language Elements and Types. But if an object field holds a reference to another object, only the reference itself will be copied, not the referred object itself. That is why such a copy is called a shallow one. To get a deep copy, one has to re-implement the clone() method and follow all the references of the tree of objects that can be quite a widespread. Fortunately, the clone() ...
Read now
Unlock full access