X
Xavier Tarrago
To retrieve your entry, you have to use as key an object that equals the
original key.
Two answers :
1 - I think that what you are triying to build is already there. It is a
WeakHashMap in jsdk 1.2 and later. (Source code is available)
------------------------------------
A hashtable-based Map implementation with weak keys. An entry in a
WeakHashMap will automatically be removed when its key is no longer in
ordinary use. More precisely, the presence of a mapping for a given key will
not prevent the key from being discarded by the garbage collector, that is,
made finalizable, finalized, and then reclaimed. When a key has been
discarded its entry is effectively removed from the map, so this class
behaves somewhat differently than other Map implementations
------------------------------------
2 - if you persist, you should derive WeakReference to overload equals()
and hash() for your key object. When you use a key (say getkey) ou will get
the right object it if for this entry (entrykey), getkey.hash() ==
entrykey.hash() and (getkey == entrykey || getkey.equals(entrykey)).
original key.
Two answers :
1 - I think that what you are triying to build is already there. It is a
WeakHashMap in jsdk 1.2 and later. (Source code is available)
------------------------------------
A hashtable-based Map implementation with weak keys. An entry in a
WeakHashMap will automatically be removed when its key is no longer in
ordinary use. More precisely, the presence of a mapping for a given key will
not prevent the key from being discarded by the garbage collector, that is,
made finalizable, finalized, and then reclaimed. When a key has been
discarded its entry is effectively removed from the map, so this class
behaves somewhat differently than other Map implementations
------------------------------------
2 - if you persist, you should derive WeakReference to overload equals()
and hash() for your key object. When you use a key (say getkey) ou will get
the right object it if for this entry (entrykey), getkey.hash() ==
entrykey.hash() and (getkey == entrykey || getkey.equals(entrykey)).