繁体   English   中英

为什么google-collection AbstractMultimap类对成员变量使用瞬态关键字?

[英]Why google-collections AbstractMultimap class use transient keyword for member variable?

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; 

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

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

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

没有。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM