HashMap<Character, Integer> map = new HashMap();
HashMap map = new HashMap<Character, Integer>();
以上两种创建HashMap的方式,有什么区别呢?
Integer a = (Integer) 1;
Object b = new Integer(1);
像这个
放后面的是什么鬼,这不就相当于没用了,起不到泛型的作用。你放前面才能规范HashMap里面的数据类型
放在等号前面,相当于给定义的变量限定了入参类型,比如HashMap<String,String> map1
,那后面就只能使用map1.put("name","tom")
,入参都只能使用String类型。
放等号后面等于没放,即与new HashMap()
等效。