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

StackOverflow https://stackoverflow.com/questions/17984503

  •  04-06-2022
  •  | 
  •  

Question

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; 
Était-ce utile?

La solution

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.

Autres conseils

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.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top