java – 类型HashMap不接受参数
发布时间:2020-12-15 04:47:10 所属栏目:Java 来源:网络整理
导读:我在 java中关注了H000Map的 this video.它有 below code. // Create the HashMapHashMapString,String hm = new HashMapString,String();// Put datahm.put("Katie","Android,WordPress");hm.put("Magda","Facebook");hm.put("Vanessa","Tools");hm.put("An
我在
java中关注了H000Map的
this video.它有
below code.
// Create the HashMap HashMap<String,String> hm = new HashMap<String,String>(); // Put data hm.put("Katie","Android,WordPress"); hm.put("Magda","Facebook"); hm.put("Vanessa","Tools"); hm.put("Ania","Java"); hm.put("Ania","JEE"); // !! Put another data under the same key,old value is overridden // HashMap iteration for (String key: hm.keySet()) System.out.println(key+":"+hm.get(key)); 所以我写了下面的代码,用它来练习HashMap(几乎相同的代码) package hashmap; import java.util.*; public class HashMap { public static void main(String[] args) { HashMap<String,String>(); hm.put("Katie",WordPress"); hm.put("Magda","Facebook"); hm.put("Vanessa","Tools"); hm.put("Ania","Java"); hm.put("Ania","JEE"); } } 但该类没有编译给出错误“类型HashMap不带参数”所以我搜索了我got this的答案 其中一个答案说
所以我导入了java.util.Map,但netbeans给出了这个错误,并说导入没有使用.然后我java.util.*;但结果是一样的.我不知道这是我的IDE故障的新手错误. 我的jdk 1.8和Windows 8.1中的Netbeans 8.0.2 解决方法
你正在命名你的类HashMap,它正在影响java.util.HashMap.只需将其重命名为其他内容即可.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容