Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Warning with Java HashMap

Eclipse is saying "HashMap is a raw type" When I use the following code

HashMap = new HashMap();

Any idea what could be wrong?

like image 503
plkMon Avatar asked Jul 28 '10 14:07

plkMon


1 Answers

Eclipse will give you that warning when you use a non-Generic HashMap using Java 5 or newer.

See Also: The Generics Lesson in Sun's Java Tutorials.

Edit: Actually, here, I'll give an example too:

Say I want to map someone's name to their Person object:

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

These are checked at compile-time; the type information is lost at run-time due to how Java implements Generics.

like image 119
Powerlord Avatar answered Oct 17 '22 08:10

Powerlord