【问题】
折腾:
结果出现警告:
Type safety: The method put(Object, Object) belongs to the raw type HashMap. References to generic type HashMap<K,V> should be parameterized |
【解决过程】
1. 参考:
去试试:
private HashMap<String, long> calcTimeKeyDict;
结果出错:
Syntax error on token "long", Dimensions expected after this token |
然后后来无意间试了试:
private HashMap<String, Long> calcTimeKeyDict;
才可以的。
2.参考:
Eclipse中HashMap/Hashtable出现警告Type safety
去改为:
private HashMap<Object, Object> calcTimeKeyDict;
也是可以的。
【总结】
java中的Map或HashMap,都是要指定对应的具体的key和value的类型的。
比如:
private HashMap<Object, Object> calcTimeKeyDict; private HashMap<String, Long> calcTimeKeyDict; private Map<String, Long> calcTimeKeyDict;
否则就会提示
Type safety: The method put(Object, Object) belongs to the raw type HashMap. References to generic type HashMap<K,V> should be parameterized |
的。
转载请注明:在路上 » 【已解决】java中使用HashMap出现警告:Type safety: The method put(Object, Object) belongs to the raw type HashMap. References to generic type HashMap<K,V> should be parameterized