The example in this article describes how Java uses serialization to achieve deep cloning of objects. Share it with everyone 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 will be helpful to everyone’s java programming.
For more articles on how Java uses serialization to achieve object deep cloning, please pay attention to the PHP Chinese website!