KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
If I iterate over the key set of a WeakHashMap, do I need to check for null values? WeakHashMap<MyObject, WeakReference<MyObject>> hm = new WeakHashMap<MyObject, WeakReference<MyObject>>(); for ( MyObject item : hm.keySet() ) { if ( item != null ) { // <- Is this test necessary? // Do something... } } In other words, can elements of the WeakHashMap be collected while I am iterating over them? EDIT For the sake of this question, one can assume that no null entries is added in the hash map.
Tags (comma-separated)
Save Edits
Cancel