HashMap中的泛型

xiaoxiao2021-03-01  20

HashMap<String,Integer> hm = new HashMap <String,Integer>;hm.put("haha",1);hm.put(1,2);//报错,因为类型不符hm.get("haha");hm.get(1);//没问题,因为它没更改数据,只是读取 由此可见,泛型在读取数据时可能不起作用,只是在写入和更新数据时才会限制类型
转载请注明原文地址: https://www.6miu.com/read-3649980.html

最新回复(0)