标签:code name hash out 实现 hashmap shm 代码 public
`import java.util.HashMap;
public class Demo9{
public static void main(String[] args){
HashMap<Integer,String> m1 = new HashMap<>();
HashMap<Integer,String> m2 = new HashMap<Integer,String>(){};
HashMap<Integer,String> m3 = new HashMap<Integer,String>(){
{
put(1,"name");
put(2,"age");
put(3,"weight");
}
};
System.out.println(m3.get(3));
}
}`
map1是一个普通的HashMap实例,但map2是一个匿名类实例,只是该匿名类继承自HashMap。map3也是一个继承自HashMap的匿名类实例,并且添加了static代码块来初始化数据
标签:code name hash out 实现 hashmap shm 代码 public
原文地址:https://www.cnblogs.com/zui-ai-java/p/14134375.html