WeakhashMap 是如何工作的?
正如weakhashmap如何理解对其键之一的引用现在已经过时,特别是如果该键是池化的字符串?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能将字符串文字与 WeakHashMap 一起使用(当然可以,但这样做没有意义):
相反,您必须使用:
在后一种情况下,字符串不会被池化。
You must not use String literals with WeakHashMap (well you can but there would be no point in it):
instead you must use:
In the latter case String is not pooled.
“过时”这个词并不精确。所讨论的情况是“垃圾收集”。当键被垃圾收集时,值将从 WeakHashMap 中删除。时期。
The word 'obsolete' is imprecise. The condition in question is 'garbage-collected'. A value is removed from the WeakHashMap when and if the key is garbage-collected. Period.