Download presentation
Presentation is loading. Please wait.
Published byAmice Flynn Modified over 9 years ago
7
Does not implement clone() method! public class Bar { … public Object clone() { … } Does not implement Cloneable interface!
8
Returns null! At least, throw CloneNotSupportedException instead!
9
Never calls super.clone()!
10
Foo public class Bar { Foo f; … public Object clone() { … clone.f = (Foo) f.clone(); … } In Java 5, use covariant return type!
13
Fields selected for deep copy
16
Complete240 clone() methods Consistent class annotation 189 classes do not implement interface 14 do not implement clone() method Returning nullNo violations Not calling super.clone()237 violations! Object as return typeIn all 240 cases
18
public class Bar extends Foo { public Object clone() { Bar clone = super.clone(); … return clone; }
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.