Java USES serialization to implement the method of object depth clone

  • 2020-04-01 04:02:27
  • OfStack

This article illustrates how Java USES serialization to implement deep clone. Share with you for your reference. The specific implementation method is as follows:


ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(byteOut);
out.writeObject(obj);
ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
ObjectInputStream in =new ObjectInputStream(byteIn);
Object newObj=in.readObject();

I hope this article has been helpful to your Java programming.


Related articles: