Skip to Content
Java Coding Problems
book

Java Coding Problems

by Anghel Leonard
September 2019
Intermediate to advanced
816 pages
18h 47m
English
Packt Publishing
Content preview from Java Coding Problems

Cloning via the Cloning library

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. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Coding Problems - Second Edition

Java Coding Problems - Second Edition

Anghel Leonard
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan
The Well-Grounded Java Developer, Second Edition

The Well-Grounded Java Developer, Second Edition

Benjamin Evans, Martijn Verburg, Jason Clark

Publisher Resources

ISBN: 9781789801415Supplemental Content