This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why HashMap is transient inside HashSet implementation?

 
Shishir R Verma
Greenhorn
Posts: 6
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Winston Gutkowski
Bartender
Pie
Posts: 9484
50
Eclipse IDE Hibernate Ubuntu
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Shishir R Verma
Greenhorn
Posts: 6
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic