`

HashMap中的泛型

阅读更多
HashMap<String,Integer> hm = new HashMap <String,Integer>;
hm.put("haha",1);
hm.put(1,2);//报错,因为类型不符
hm.get("haha");
hm.get(1);//没问题,因为它没更改数据,只是读取

由此可见,泛型在读取数据时可能不起作用,只是在写入和更新数据时才会限制类型
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics