Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HashMap in Java Not Working

This is currently my second day coding in Java, no worries though I am not new to coding. Anyhow, I am not use to not having dictionaries like Python has, which can store a Key and Value.

That is when I came upon Java HashMaps. Currently, I can not seem to get them to work, and I am unsure why. Here is the code I am using, but these seems to be raising errors:

 Map<String, String> visual = new HashMap<String, String>();

Then here is the error it is generating:

Multiple markers at this line
    - The type Map is not generic; it cannot be parameterized with arguments <String, String>
    - HashMap cannot be resolved to a type

I am even importing the Hash libraries:

import java.util.Map;
import java.util.HashMap;

So simply my question is, why is the HashMap not working? Thank you! :)


P.S. Here is my little piece of code:

public Map areaTotal() {
    Map<String, String> visual = new HashMap<String, String>();
    return visual;
}

EDIT

Sorry, I guess I did forget to include some other information.

  • Using Eclipse
  • Only other import is Math
like image 906
Michael Jones Avatar asked Jul 14 '26 22:07

Michael Jones


1 Answers

You probably have another Map class in the same package which is not generic - this should be removed or renamed to something else

like image 59
Reimeus Avatar answered Jul 16 '26 10:07

Reimeus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!