File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Bruce Jin
Ranch Hand
Posts: 672
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to make a copy of an object without using Object.clone()?
Thanks!
 
Simon Percivall
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you facing some technical issue in using clone or is this a Quiz kind of question?
 
Bruce Jin
Ranch Hand
Posts: 672
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic