HashMap savedStuff = new HashMap();
savedStuff.put("symbol", this.symbol); //this is a string
savedStuff.put("index", this.index); //this is an int
给我警告:
HashMap is a raw type. References to generic type HashMap<K,V> should be parameterized
最佳答案
HashMap<String, Object> savedStuff = new HashMap<String, Object>();
当然,在提取元素时您仍然需要注意使用正确的类型。
关于java - 如何正确使用HashMap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3640648/