Java Reference
In-Depth Information
try {
return super.clone();
} catch (CloneNotSupportedException ex) {
return null;
}
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof Team) {
Team other = (Team) obj;
return other.getName().equals(this.getName())
&& other.getCity().equals(this.getCity());
} else {
return false;
}
}
}
Next, to make a deep copy of a Team object, the clone() method needs to be
called against that object. To make a shallow copy of the object, the shal-
lowCopyClone() method must be called. The following code demonstrates this
technique:
Team team1 = new Team();
Team team2 = new Team();
team1.setCity("Boston");
team1.setName("Bandits");
team2.setCity("Chicago");
team2.setName("Wildcats");
Search WWH ::




Custom Search