I found out that the keyword transientprevents the storage of the values of the instance fields declared with the keyword transientwhen the object is serialized.
Below is the code from java.util.HashMap:
public class HashMap<K,V> extends AbstractMap<K,V>
implements Map<K,V>, Cloneable, Serializable {
....
static class Node<K,V> implements Map.Entry<K,V> {...}
transient Node<K,V>[] table;
}
Why are instance field values tablenot part of serialization? Because the field values tableare the actual contents of the instance class HashMapin terms of implementation.
Note: here is one exercise to use the transient keyword.
source
share