Skip to content

Commit 2a6c2d1

Browse files
[add] map vs hashMap
1 parent 668ff03 commit 2a6c2d1

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package DGenericContainer.Map_HashMap;
2+
3+
import java.util.Collections;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
7+
/**
8+
* @ClassName MapHashMap
9+
* @Description
10+
* @Date 2022/9/20 11:39
11+
* @Version 1.0.0
12+
**/
13+
public class MapHashMap {
14+
public static void main(String[] args) {
15+
HashMap<String, String> hashMap=new HashMap<>();
16+
//错误示例:Collections.emptyMap()的返回类型为Map
17+
//HashMap<String, String> hashMap1=Collections.emptyMap();
18+
useHashMap(hashMap);
19+
Map<String, String> map=new HashMap<>();
20+
//错误示例:方法参数为hashMap类型
21+
//useHashMap(map);
22+
Map<String, String> map1= Collections.emptyMap();
23+
//错误示例:方法参数为hashMap类型
24+
//useHashMap(map1);
25+
}
26+
27+
public static void useHashMap(HashMap<String, String> hashMap){
28+
29+
}
30+
}

0 commit comments

Comments
 (0)