-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWeakHashMapDemo.java
More file actions
40 lines (34 loc) · 974 Bytes
/
WeakHashMapDemo.java
File metadata and controls
40 lines (34 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.bywlstudio.refence;
import java.util.HashMap;
import java.util.WeakHashMap;
public class WeakHashMapDemo {
public static void identHashMap(){
HashMap<Integer,String> hashMap = new HashMap();
Integer integer = new Integer(1);
hashMap.put(integer,"MakerStack");
System.out.println(hashMap);
integer = null ;
System.gc();
//取消强引用
try{
}finally {
System.out.println(hashMap);
}
}
public static void weakHashMapTest(){
WeakHashMap<Integer,String> hashMap = new WeakHashMap();
Integer integer = new Integer(1);
hashMap.put(integer,"MakerStack");
System.out.println(hashMap);
integer = null ;
System.gc();
//取消强引用
try{
}finally {
System.out.println(hashMap);
}
}
public static void main(String[] args) {
weakHashMapTest();
}
}