*
The moose likes EJB and other Java EE Technologies and the fly likes shallow cloning and deep cloning Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "shallow cloning and deep cloning " Watch "shallow cloning and deep cloning " New topic
Author

shallow cloning and deep cloning

Aaron Raja
Ranch Hand

Joined: Jun 07, 2007
Posts: 206
What is the main difference between shallow cloning and deep cloning of objects?


Thanks, AR
SCWCD 5, SCJP 1.4, OCA (PL/SQL)
Steve Wink
Ranch Hand

Joined: May 13, 2002
Posts: 223
Originally posted by Aaron Rhena:
What is the main difference between shallow cloning and deep cloning of objects?


Lets say you have an object which contains other objects which contain others etc. Basically, you have a complex tree of objects. A deep copy would go into each of these objects and create a copy of each of them. A shallow copy would copy the first ( outer ) object, and then copy references to the existing objects, rather than create copies of them.
 
Don't get me started about those stupid light bulbs.
 
subject: shallow cloning and deep cloning
 
Similar Threads
Creating a copy of an object
Difference between obj1 = obj.clone() and obj1= obj
serialization
cloning question
shallow cloning and deep cloning