Every once in a while I need a HashMap with weakly referenced values. But since the standard HashMap with weak references in Java only has weak keys, which I never found any use for so far, I find myself googeling for an implementation I can cut n paste into my projects every time I need one.

Last time I needed one I found MapMaker i Guava. So this is a note to myself for next time.

Map<String, Object> map = new MapMaker().weakValues().makeMap();

Leave a Reply

Your email address will not be published. Required fields are marked *