The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


RE:Help me in deep copy

Posted by Alex on February 04, 2002 at 3:27 PM

> I have a class one of whose attributes is a interface. A interface can not be clonable so how can I deepcopy the class. On the other hand, how to deep copy a list if the item of the list is a unknown object?

> thanks very much.

Create another interface that extends your interface and extends Serializable also. Let all your classes implement Serializable interface. This way you can use ObjectOutputStream to write this object some output stream, from which you can read back your object. This will enable you to create new copy of your object. This is pain in the ass, but what can you do. If your project is really big - good luck.
Remember, all third party classes also must be extended to implement Serializable, otherwise ObjectOutputStream's method writeObject will throw you an NotSerializableException.

  • Deep Copy Matt Gerrans February 05, 2002 at 8:41 PM (0)
  • Deep Copy Matt Gerrans February 05, 2002 at 8:40 PM (0)

Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us