HashMap和Map的道道

来源:互联网 发布:时尚的网络用语 编辑:程序博客网 时间:2024/05/16 00:59

先看api:

Class HashMap<K,V>    java.lang.Object        java.util.AbstractMap<K,V>            java.util.HashMap<K,V>     Type Parameters:        K - the type of keys maintained by this map        V - the type of mapped values    All Implemented Interfaces:        Serializable, Cloneable, Map<K,V>    Direct Known Subclasses:        LinkedHashMap, PrinterStateReasons 

!!敲黑板!!
一定要注意,HashMap 是泛型类(class),它实现了Map接口。
请不要实例化接口!

HashMap<String,String> t=new map<String,String>();HashMap t=new map<String,String>();//我的花式写错过程

正确写法:

HashMap map =  new HashMap<Integer,String>();

ps:终于会设置markdown的颜色了!

原创粉丝点击