• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

clone interface

 
Steven Coddington
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Saket Barve
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an example of what Ernest describes above:
Shallow Vs. Deep Cloning

Regards,
Saket
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic