September 2019
Intermediate to advanced
816 pages
18h 47m
English
A deep copy is needed when an object depends on another object. Performing a deep copy means copying the object, including its chain of dependencies. For example, let's assume that Point has a field of the Radius type:
public class Radius { private int start; private int end; // getters and setters}public class Point { private double x; private double y; private Radius radius; public Point(double x, double y, Radius radius) { this.x = x; this.y = y; this.radius = radius; } // getters and setters}
Performing a shallow copy of Point will create a copy of x and y, but will not create a copy of the radius object. This means that modifications that affect the radius object will be reflected in the clone as well. ...