weakhashmap如何工作? [英] how does weakhashmap work?

查看:86
本文介绍了weakhashmap如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

/ b>

 <$ c $ 

你不能在WeakHashMap中使用字符串文字(你可以,但不会有任何意义): c> String myKey =somekey;

您必须使用:

 字符串myKey = new String(somekey); 

在后一种情况下,字符串不会合并。


As in how does weakhashmap understand that a reference to one of its key is obsolete now especially if the key is a String which is pooled?

解决方案

You must not use String literals with WeakHashMap (well you can but there would be no point in it):

String myKey = "somekey";

instead you must use:

String myKey = new String("somekey");

In the latter case String is not pooled.

这篇关于weakhashmap如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆