MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerTIL/comments/77yhd5/java_hashsett_just_uses_hashmapt_object_behind/doqop3u/?context=3
r/ProgrammerTIL • u/c0d3m0nky • Oct 22 '17
https://imgur.com/a/A26Th
35 comments sorted by
View all comments
Show parent comment
2
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?
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."
1
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."
View all comments
Show parent comment
2
u/pi_rocks Oct 22 '17
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?