«
Prev
»
Next
Java / Object, Class and Package
Difference between shallow and deep copy in Java.
| Shallow copy. | Deep copy. |
| Cloned Object and the original object are not 100% disjoint. | Cloned Object and original object are 100% disjoint. |
| Any changes to the cloned object will be reflected in original object or vice versa. | Changes made to cloned object won't be reflected to original object or vice versa. |
| Default version of clone method creates the shallow copy of an object. | To create the deep copy of an object, you have to override clone method. |
| Shallow copy is preferred if an object has only primitive fields. | Deep copy is preferred if an object has references to other objects as fields. |
| Shallow copy is fast and cost effective. | Deep copy is slow and very expensive. |
More Related questions...
Comments & Discussions