Java deep copy library

前端 未结 5 1390
青春惊慌失措
青春惊慌失措 2020-12-18 08:27

Is there library that can make deep copy?

ex) normal object, array, list, inputstream etc.

5条回答
  •  不思量自难忘°
    2020-12-18 08:37

    @Konrad's posting is spot on. The only general way of doing deep copying is to use a Java serialization mechanism.

    Obviously, it is expensive.

    The other caveat is that some Java objects are impossible to copy by serialization. Examples include

    • Thread and subclasses cannot be serialized because a thread's execution state cannot be serialized.

    • Streams in general cannot be serialized because you cannot get at the state of the stream that has already been written (writers, output streams) or that is yet to be read (readers, input streams). (Indeed, in the reader / input stream case, that state may literally be infinite.)

    • GUI components cannot be serialized because they depend on the (external) graphics environment which can't be serialized.

提交回复
热议问题