Questions tagged [weakhashmap]

A special data structure in Java, a WeakHashMap is a hashtable-based Map with weak keys, meaning when a key has been discarded its entry is effectively removed from the map.

Java's WeakHashMap is a hashtable-based Map with weak keys, meaning when a key has been discarded its entry is effectively removed from the map.

This class is intended primarily for use with key objects whose equals methods test for object identity using the == operator. Once such a key is discarded it can never be recreated, so it is impossible to do a lookup of that key in a WeakHashMap at some later time and be surprised that its entry has been removed.

77 questions
0
votes
1 answer

Java WeakHashMap reference not being updated

In the code below I create a Pen object and initialize it's color to white. In the constructor of Pen, after setting the field 'penColor' to the value passed into the constructor, I update a global static weak hashmap that I'm keeping where the KEY…
Amir Afghani
  • 37,814
  • 16
  • 84
  • 124
0
votes
1 answer

Java : how does weakhashmap determine if the key is 'obsolete' or not?

How does it know this key is old and ready to throw it away ? and why string literal ? For example, private static WeakHashMap<, String> m = new WeakHashMap<, String>(); public…
peter
  • 8,333
  • 17
  • 71
  • 94
1 2 3 4 5
6