Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OOP-4 Lookup hashmap

 
K. Tsang
Bartender
Posts: 3521
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I once done this assignment a while back and now trying to enhance it and stuff. But I found a potential problem with my implementation.

When the hashmap is created should the value be a "Thing" or "String" through the getDescription() method?
eg HashMap<Integer, String> hMap ... or HashMap<Integer,Thing> hMap ...
assuming I populate the hashmap like this:
hMap.put(1, new BookOnTape()); //<Integer,Thing>
hMap.put(1, new BookOnTape().getDescription()); //<Integer,String>

Another way of asking is once the hashmap is populated, should the Thing's serial number be the same as the hashmap key?

Thanks
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The value should be a Thing.

It is ok if the Thing's serial number is the same as the hashmap key, but the value should be the Thing, not the Thing's description.
 
K. Tsang
Bartender
Posts: 3521
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marilyn, I got the serial number same as hashmap key
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic