Jacob wrote:
> A natural choice whould be to use WeakReference as
> keys:
>
> HashMap map = new HashMap();
> String key = "KEY";
> map.put (new WeakReference (key), "VALUE");
>
> But neither of these approaches will return me
> the value:
>
> h.get ("KEY"); // returns null
> h.get (new WeakReference ("KEY")); // returns null
>
> Any ideas?
Use java.util.WeakHashMap. In fact, this is one of the rare cases where
you actually *want* to use WeakHashMap. Most people who try to use the
class are misunderstanding its functionality. (Specifically, note that
is uses weak keys rather than weak values, which meets your needs just
fine but is counterintuitive to most everyone else.)
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation