简体   繁体   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 https://code.google.com/p/google-collections/source/browse/trunk/src/com/google/common/collect/AbstractMultimap.java?r=117

AbstractMultimap is implements Serializable. AbstractMultimap实现了Serializable。

In my eyes actual datas are saved to map and totalSize variables. 在我看来,实际数据保存在map和totalSize变量中。

But both variables are declared with transient keyword. 但是这两个变量都用transient关键字声明。

This fact means that there's no serialization right? 这个事实意味着没有序列化吗?

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

That's because the AbstractMultimap class doesn't actually contain the backing Map implementation; 这是因为AbstractMultimap类实际上并不包含支持Map实现。 that's provided by the concrete subclass, which is responsible for managing serialization: 由具体的子类提供,它负责管理序列化:

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

This fact means that there's no serialization right? 这个事实意味着没有序列化吗?

No. 没有。

It means that those fields are not serialized by the default serialization mechanism. 这意味着这些字段不会通过默认的序列化机制进行序列化。 The state is actually being serialized in the writeObject() method ... of a child class. 状态实际上是在子类的writeObject()方法中序列化的。

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

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