Forums Register Login

Why HashMap is transient inside HashSet implementation?

+Pie Number of slices to send: Send
Hi,

This question might have been asked earlier and probably a dumb question to ask, but It is somehow stuck in my mind.
I was looking at the code of HashSet, which actually looks like a wrapper around HashMap. I noticed that the HashSet class is implementing Serializable and HashMap is declared as transient variable inside it. Why HashMap is transient?

Thanks in advance...
1
+Pie Number of slices to send: Send
 

Shishir Rmv wrote:I was looking at the code of HashSet, which actually looks like a wrapper around HashMap. I noticed that the HashSet class is implementing Serializable and HashMap is declared as transient variable inside it. Why HashMap is transient?


Almost certainly because a HashSet can be translated into a more compact serialized form than an equivalent HashMap; but at the end of the day, without talking to the designer, it's pure speculation.

Perhaps a bit more source-code gazing is in order.

Winston
+Pie Number of slices to send: Send
 

Winston Gutkowski wrote:
Almost certainly because a HashSet can be translated into a more compact serialized form than an equivalent HashMap; but at the end of the day, without talking to the designer, it's pure speculation.

Winston



Thanks Winston. That's what I was thinking. And in the end of the day while deserialzing it back, it loses its compactness anyways.
Ruth Stout was famous for gardening naked. Just like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1429 times.
Similar Threads
Why HashMap.Entry is transient?
HashMap Vs. HashSet
5 simple J2EE test questions
How is serialization handled with transient variables defined in Collections ?
What is a HashSet?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:22:36.