| Author |
clone interface
|
Steven Coddington
Greenhorn
Joined: Oct 17, 2004
Posts: 10
|
|
|
I need to do a deep copy of an object with both primative and String type variables. "clone" returns a copy with values for primatives and references for non-primative String ( I think). Is there an alternative to clone() that does deep, or can someone help me write an alternative.
|
Steve Coddington
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24061
|
|
|
You can override clone() with your own version with deep-copy semantics. Depending on the class, this might be as simple as calling super.clone() to get a shallow copy, and then calling clone() on each of your member objects, installing the copies inside your shallow copy, and then returning it.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Saket Barve
Ranch Hand
Joined: Dec 19, 2002
Posts: 224
|
|
Here is an example of what Ernest describes above: Shallow Vs. Deep Cloning Regards, Saket
|
 |
 |
|
|
subject: clone interface
|
|
|