HashMap类型不是通用的;它不能用参数< String,Integer>参数化。 [英] The type HashMap is not generic; it cannot be parameterized with arguments <String, Integer>

查看:141
本文介绍了HashMap类型不是通用的;它不能用参数< String,Integer>参数化。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试实现如下地图时,这是一个奇怪的错误。

This is a strange error i am getting today when i try to implement a Map as below.

Map<String, Integer> cache = new HashMap<String, Integer>();

我使用 JDK 1.7 并且不确定为什么会出现此错误并通过添加强制转换来更改上面的行会删除错误。 我在发布此问题之前查看了stackoverflow中的相关帖子似乎是一个奇怪的问题。

I am using JDK 1.7 and not sure why this error has been coming and changing the above line by adding cast removes the error. I looked at the related posts in stackoverflow before posting this question seems to be strange issue.

Map<String, Integer> cache = (Map<String, Integer>) new HashMap();


推荐答案

检查您实际上是否正在使用 java.util 导入中的.HashMap java.util.Map

Check you are actually using java.util.HashMap and java.util.Map in your imports.

这篇关于HashMap类型不是通用的;它不能用参数&lt; String,Integer&gt;参数化。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆