简体   繁体   中英

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 is implements Serializable.

In my eyes actual datas are saved to map and totalSize variables.

But both variables are declared with transient keyword.

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; 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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