aspose file tools*
The moose likes Beginning Java and the fly likes clone interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "clone interface" Watch "clone interface" New topic
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: 24187
    
  34

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: 229
Here is an example of what Ernest describes above:
Shallow Vs. Deep Cloning

Regards,
Saket
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: clone interface