The type HashMap is not generic; it cannot be parameterized with arguments



This is a strange error i am getting today when i try to implement a Map as below.

Map<String, Integer> cache = new HashMap<String, Integer>();

I am using JDK 1.7 and not sure why this error has been coming and changing the above line by adding cast removes the error. I looked at the related posts in stackoverflow before posting this question seems to be strange issue.

Map<String, Integer> cache = (Map<String, Integer>) new HashMap();

Answer

Check you are actually using java.util.HashMap and java.util.Map in your imports.



Source: stackoverflow