Eclipse Warning with Java HashMap

Eclipse says “HashMap is a raw type.” When I use the following code

HashMap = new HashMap();

Any idea what could be wrong?

+5
source share
8 answers

Eclipse will give you this warning if you are using Generic HashMap using Java 5 or later.

See also: “Lesson Lesson” in Sun Java Tutorials.

Edit: Actually, here I will also give an example:

Say I want to label someone with my object Person:

Map<String, Person> map = new HashMap<String, Person>();
// The map.get method now returns a Person
// The map.put method now requires a String and a Person

They are checked at compile time; type information is lost at runtime due to the way Java implements Generics.

+17

, . , , , . :

Map<String, Integer> map = new HashMap<String, Integer>();
+3

, .. , eclipse java 1.4

+1

Try

HashMap<String,Integer> map = new HashMap<String,Integer>();

(, (String) (Integer)).

+1

, .

....

0

. . , , HashMap String Integer.

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

These are all valid answers, you can also use the @SurpressWarnings annotation to get the same result without resorting to the actual generics .;)

0
source

hashmap is a raw type and therefore must be parameterized, i.e. that ever the data we get through the haspmap function, its type must be declared in order to receive its functions

eg

HashMap<String, Integer> map = new HashMap<String, Integer>();
0
source

All Articles