Presentation is loading. Please wait.

Presentation is loading. Please wait.

Does not implement clone() method! public class Bar { … public Object clone() { … } Does not implement Cloneable interface!

Similar presentations


Presentation on theme: "Does not implement clone() method! public class Bar { … public Object clone() { … } Does not implement Cloneable interface!"— Presentation transcript:

1

2

3

4

5

6

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!

11

12

13 Fields selected for deep copy

14

15

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

17

18 public class Bar extends Foo { public Object clone() { Bar clone = super.clone(); … return clone; }

19

20

21

22

23


Download ppt "Does not implement clone() method! public class Bar { … public Object clone() { … } Does not implement Cloneable interface!"

Similar presentations


Ads by Google