Java深拷贝库 [英] Java deep copy library

查看:191
本文介绍了Java深拷贝库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可以进行深层复制的库?

Is there library that can make deep copy?

ex)普通对象,数组,列表,输入流等。

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

推荐答案

@ Konrad的帖子就是现货。进行深度复制的唯一一般方法是使用Java序列化机制。

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

显然,它很昂贵。

另一个警告是,某些Java对象无法通过序列化进行复制。示例包括

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组件无法序列化,因为它们依赖于(外部)图形环境无法序列化。

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

这篇关于Java深拷贝库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆