Difference between using Map and HashMap as declared type

Viewed 5215

What's the difference between the following two declaration statements:

HashMap<Character, Character> map = new HashMap<Character, Character>();

Map<Character, Character> map = new HashMap<Character, Character>();

Any advantages of using the interface Map instead of HashMap in this particular case?

In the following case, is Map definitely better because the method can accept different types of maps?(if it is intended to)

public void method(Map map){

}
3 Answers
Related