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();
The type HashMap is not generic; it cannot be parameterized with arguments <String, Integer> If this type of error occur than first check your file name and class name Beause by mistake you save file name as HashMap.java Than try other ways what do you mean by HashMap is not generic.
We've got a class that Extends HashMap and then implements a custom Interface. Type safety: The method put (Object, Object) belongs to the raw type HashMap. References to generic type HashMap<K,V> should be parameterized
The type List is not generic; it cannot be parameterized with arguments. In Java, the java.util and java.awt packages both define a type called List. The util version is the collections interface that is commonly used. The awt version is a class used for creating a dropdown list GUI element.
Check you are actually using java.util.HashMap and java.util.Map in your imports.
I have also gone through the same error but it was resolved just by changing some properties of the project:
Properties
Java Build Path
from right-hand side panelOrder and Export
tabJRE System Library or JDK Library
Up
button and move it to first positionOk
Do repeat this for all other dependents project as well, if you have dependencies.
It resolved my issue because previously the Java files were picking other libraries and packages not from JRE package as it was ordered set in last priority.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With