WeakHashMap的清除问题
代码如下:
---------------------------------------------------------------------------------------------------
import java.util.*;
public class Test14 {
public static void main(String[] args) {
Map<String, String> map=new WeakHashMap<String, String>();
map.put("3", "future");
map.put("2", "good");
map.put(new String("1"), "LLL");
System.out.println(map); //此处输出的是{1=LLL, 2=good, 3=future}
System.gc();
System.out.println(map); //而此处输出的是{2=good, 3=future}
}
}
为什么改成"new String('1')"才能被清除?