最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】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

Java crifan 13016浏览 0评论

【问题】

折腾:

【已解决】Java中的字典类型变量

结果出现警告:

Type safety: The method put(Object, Object) belongs to the raw type HashMap. References to generic type HashMap<K,V> should be parameterized

Type safety The method put Object Object  belongs to the raw type HashMap

【解决过程】

1. 参考:

关于HashMap的安全报错问题的解决

去试试:

private HashMap<String, long> calcTimeKeyDict;

结果出错:

Syntax error on token "long", Dimensions expected after this token

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

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.177 seconds, using 22.15MB memory