This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
OK, so why does it matter? I understand the difference between the two (effectively creating a pointer, versus setting the variables equal), but my book does not state why deep copy may be better. Can anyone provide me with a response?
Hello. My name is Inigo Montoya. You killed my father. Prepare to die.
The caller of Copy has a reference to the original list. With a shallow copy, the caller's changes are seen by Copy and Copy's changes are seen by the caller. This can introduce some subtle side effects.
Jeanne has deep knowledge, so I will leave it to the OO'rs to explain it in OO terminology.
A shallow copy just makes another one, without transferring ( copying ) the values. A deep copy does something along the lines of for each item in source collection, set value in new collection to same as source collection.
This may involve the new operartor, many fundamental classes that are often used allow a reference to same kind as a constructor paramater and result in a totally new object which will not pass-through to the source complex object.
Anything other than a primitive would likely be a complex object, most any instance of a class is.
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Joined: Sep 17, 2006
[ January 30, 2008: Message edited by: Nicholas Jordan ]