Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HashMap code repetition

 
Ramakrishnan Viswanathan
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a HashMap with 10 entries. I have 2 classes that need to use this HashMap. Unfortunately these 2 classes are not related to each other in any way.

I have ended up with a situation where I have to repeat the code for creating and populating the HashMap in both the classes.

Is there any way I can avoid this code duplication?

Thanks in Advance
Ram
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Populate the HashMap in a class which is accessable by both.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, please see this document.
 
Ramakrishnan Viswanathan
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I apologize for posting this in two places. I am really sorry about that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic