博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WeakedHashMap 的例子
阅读量:6994 次
发布时间:2019-06-27

本文共 720 字,大约阅读时间需要 2 分钟。

hot3.png

WeakedHashMap会在key对象已经没有引用时,如果调用System.gc()会尝试remove这个key
import java.util.*;public class WeakedHashMap {    public static void main(String args[]){    	Map
map = new WeakHashMap
(); //Map
map = new HashMap
(); String alibaba = new String("TEST"); map.put(alibaba, "TEST"); while (map.containsKey("TEST")) { try { Thread.sleep(500); alibaba = null; } catch (InterruptedException ignored) { } System.out.println("Checking for empty"); System.gc(); } }}

转载于:https://my.oschina.net/u/138995/blog/173239

你可能感兴趣的文章