How to correctly use HashMap?

Sheehan Alam picture Sheehan Alam · Sep 4, 2010 · Viewed 36.5k times · Source
HashMap savedStuff = new HashMap();
savedStuff.put("symbol", this.symbol); //this is a string
savedStuff.put("index", this.index); //this is an int

gives me the warning:

HashMap is a raw type. References to generic type HashMap<K,V> should be parameterized  

Answer

Matthew Flaschen picture Matthew Flaschen · Sep 4, 2010
HashMap<String, Object> savedStuff = new HashMap<String, Object>();

Of course, you will still have to be careful to use the right type when extracting elements.