如何在java中序列化列表? [英] How to Serialize a list in java?
问题描述
我想深度克隆一个列表.为此,我们有一个方法
//apache 公共方法.这个对象应该是可序列化的SerializationUtils.clone(对象)
所以现在要克隆我的列表,我应该先将其转换为可序列化.是否可以将列表转换为可序列化列表?
java.util.List
的所有标准实现都已经实现了 java.io.Serializable
.>
所以即使 java.util.List
本身不是 java.io.Serializable
的子类型,将列表转换为 Serializable 应该是安全的
,只要您知道它是 ArrayList
或 LinkedList
等标准实现之一.
如果您不确定,请先复制列表(使用类似new ArrayList(myList)
),然后您就知道它是可序列化的.
I would like to deep clone a List. for that we are having a method
// apache commons method. This object should be serializable
SerializationUtils.clone ( object )
so now to clone my List i should convert that to serializable first. Is it possible to convert a List into Serializable list?
All standard implementations of java.util.List
already implement java.io.Serializable
.
So even though java.util.List
itself is not a subtype of java.io.Serializable
, it should be safe to cast the list to Serializable
, as long as you know it's one of the standard implementations like ArrayList
or LinkedList
.
If you're not sure, then copy the list first (using something like new ArrayList(myList)
), then you know it's serializable.
这篇关于如何在java中序列化列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!