aspose file tools*
The moose likes Java in General and the fly likes How to make a copy of an object without using Object.clone()? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to make a copy of an object without using Object.clone()?" Watch "How to make a copy of an object without using Object.clone()?" New topic
Author

How to make a copy of an object without using Object.clone()?

Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
How to make a copy of an object without using Object.clone()?
Thanks!


BJ - SCJP and SCWCD
We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design

Crazy Bikes created by m-Power
Simon Percivall
Greenhorn

Joined: Jul 25, 2002
Posts: 3
If you can serialize it, there might be a way. I don't remember the details though. Otherwise, you out of luck.
Hari Gangadharan
Ranch Hand

Joined: Mar 08, 2001
Posts: 73
Are you facing some technical issue in using clone or is this a Quiz kind of question?


<B>Hari Gangadharan</B><BR>Unix is user friendly..<BR>but it chooses to whom it is friendly with!
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 666
Sometimes I need to save a copy of a object so that later I can compare the object with the saved one to see if anything has changed. I am thinking there maybe a simple way to make a copy of a object without implementing Clonable and override clone() in my class.
Thanks
Gopi Balaji
Ranch Hand

Joined: Jan 23, 2003
Posts: 84
Originally posted by Bruce Jin:
Sometimes I need to save a copy of a object so that later I can compare the object with the saved one to see if anything has changed. I am thinking there maybe a simple way to make a copy of a object without implementing Clonable and override clone() in my class.
Thanks

Check out the Memento pattern in the GoF book.
Must add that it is not a simple solution (but worth the while considering it).
-GB.
[ February 04, 2003: Message edited by: Gopi Balaji ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Another option is using the ObjectOutputStream to write the object to disk, then read it back in when you need to compare into a new object. Might be a performance issue though.


GenRocket - Experts at Building Test Data
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make a copy of an object without using Object.clone()?