Sidd K
Sidd K

Reputation: 97

CopyOnWriteArrayList internal state is transient

CopyOnWriteArrayList is marked Serializable. But it's internal state is transient. Can anyone please answer what are we trying to serialize in this type of List.

/** The array, accessed only via getArray/setArray. */
private volatile transient Object[] array;

Upvotes: 2

Views: 203

Answers (1)

Vikdor
Vikdor

Reputation: 24134

The writeObject method has been overridden to store the state in specific manner. So the actual store, i.e. array being transient is not affecting the serialization of a CopyOnWRiteArrayList object.

The transient members in an object will be left during the default serialization process by the JVM. But, if you override writeObject(), then that method definition will be used for serializing the object instead of the default serialization strategy.

Upvotes: 4

Related Questions