r/ProgrammerTIL • • Oct 22 '17

Other [Java] HashSet<T> just uses HashMap<T, Object> behind the scenes

76 Upvotes

35 comments sorted by

View all comments

Show parent comment

1

u/almightykiwi Oct 22 '17

Good question. Not an expert either, but I see that HashSet#writeObject starts like this :

private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {
    // Write out any hidden serialization magic
    s.defaultWriteObject();

According to the doc of ObjectOutputStream, defaultWriteObject() "writes the non-static and non-transient fields of the current class to this stream."