Originally posted by Isuru Sampath:
Would be the best choice since you get all the functionalities of Map along with the HashMap. There is no obvious point in creating a HashMap and assigning it to a Map handle since you know the object type when you're writing the code. No need to use Map unless you have no other choice.
No, that is normally
not the best choice.
You should program to an interface, not to an implementation. If you use:
Map map = new HashMap();
then it is very easy to replace the HashMap by for example a TreeMap, or another implementation of the Map interface, if that's necessary later on - without the need to change the rest of the application.
The rest of the application doesn't normally need to know exactly which implementation of Map is used.
This allows you to have a less tight coupling between parts in the application. Loose coupling is better than tight coupling.