为什么google-collections AbstractMultimap类使用transient关键字作为成员变量?

时间:2013-08-01 02:55:33

标签: java guava transient

https://code.google.com/p/google-collections/source/browse/trunk/src/com/google/common/collect/AbstractMultimap.java?r=117

AbstractMultimap是实现Serializable。

在我看来,实际数据会保存到map和totalSize变量中。

但是这两个变量都是用transient关键字声明的。

这个事实意味着没有序列化权利吗?

private transient Map<K, Collection<V>> map;
private transient int totalSize; 

2 个答案:

答案 0 :(得分:2)

那是因为AbstractMultimap类实际上并不包含支持Map实现;这是由具体的子类提供的,它负责管理序列化:

For serialization to work, the subclass must specify explicit
readObject and writeObject methods.

答案 1 :(得分:2)

  

这个事实意味着没有序列化权利吗?

没有

这意味着默认序列化机制不会序列化这些字段。该状态实际上是在子类的writeObject()方法中序列化的。