• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is this a good way to describe how hashCode works?  RSS feed

 
Dan Kaplan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I spent a lot of time trying to come up with a good metaphor for this and settled on a Wall Poster Display to describe a list and then "upgrade" the analogy to turn it into a hashmap/set. Let me know what you think about this analogy and if my article is easy to understand. Thanks!

http://www.sleepeasysoftware.com/heres-what-javas-hashcode-does/
 
Jude Niroshan
Ranch Hand
Posts: 132
5
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice post. I could understand how the hashcodes working. I have bump. According to your analogues, will different kinds of thing can appear in a one frame. Something like, one frame contains game posters and movie poster? Could you please explain it relate to Java ?
 
Dan Kaplan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jude,

Yes, that is possible but it has more to do with Java and its object oriented capabilities than with hashcode/HashSet.

As an example, you could have a Poster class and a Game Poster class that extends Poster. Then you could have a Movie Poster class that also extends Poster. Now, if you have a HashSet that takes a list of Posters, you can put both Movie Posters and Game Posters in it. You can also create a HashSet that only lets you pass in Game Posters. If you tried to put a Movie Poster into it, your code will error when you try to compile.

This is done through a java concept called Generics. You can learn more about the specific details here: http://docs.oracle.com/javase/tutorial/java/generics/

I hope that helps!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!