Win a copy of The Career Toolkit this week in the Jobs Discussion forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Is this a good way to describe how hashCode works?

 
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/
 
Ranch Hand
Posts: 135
5
Eclipse IDE Postgres Database Java
  • 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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic