My guess is that HashSet implements its own serialization logic as an optimisation: since the objects in the set are stored as keys in the map, serializing the values is useless and wasteful.
Thus the map is marked as transient, and HashSet implements the methods writeObject and readObject to provide its own serialization that ignores the values in the map.
Sorry if I don't know what I'm talking about, but wouldn't implementing read/writeObject, be enough to prevent the built in serialization from being used?
View all comments
Show parent comment
6
u/almightykiwi Oct 22 '17 edited Oct 22 '17
My guess is that HashSet implements its own serialization logic as an optimisation: since the objects in the set are stored as keys in the map, serializing the values is useless and wasteful.
Thus the map is marked as transient, and HashSet implements the methods writeObject and readObject to provide its own serialization that ignores the values in the map.
edit: grammar