
Signature
Daniel Dyer
http://www.dandyer.co.uk
>> I should have seen this coming, since Cloneable is an empty interface,
>> and the docs state that
[quoted text clipped - 11 lines]
> Cloning in Java was not very well thought-out. You could use reflection
> to invoke the clone method.
Note, though, that clone() (by default, at least) is a shallow clone, so
changes made to objects that are fields of your working copy may not be
undone by reverting to your original. What might work better for you
(depending on your requirements, which are unstated) is to save the object
by writing it to a DataOutputStream, and restoring it by reading it back
from that stream. This will do the equivalent of a deep clone, and works
for many objects that do not implement Clonable.
Stefan Schmiedl - 14 Aug 2006 06:49 GMT
> Note, though, that clone() (by default, at least) is a shallow clone, so
> changes made to objects that are fields of your working copy may not be
[quoted text clipped - 3 lines]
> from that stream. This will do the equivalent of a deep clone, and works
> for many objects that do not implement Clonable.
That's a nice idea, actually. Especially since I could tweak my
program so that I would need to do this only once per session.
Thanks,
s.