This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
It is not possible for a generic HashMap to hold HashMaps and Strings (unless you're using a Object reference but that will nullify the advantages of generics). A solution would be do separate the 2 Maps in 2 classes and use a common interface to access them.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Campbell was trying to hint that it should be Map<String, Map>.
Joined: Feb 10, 2001
thanks John...had doubt abt it but was't sure , but now not able to understand the difference between HashMap<String, HashMap> and Map<Stgring,Map> can you explain ?
John de Michele
Joined: Mar 09, 2009
It's the idea of programming against interfaces, rather than implementations. For example, if I do this:
I'm locking myself into an implementation - which may at some later point be difficult to change, or may be impossible to change if I expose methods in a public API.
If I do this:
I can be assured that if I need to make a change at a later date (say, like it turns out that a TreeMap would work better), then all I have to do is change that one line of code, and I don't have to worry about my class' public API.