views:

257

answers:

1

One of my favourites from apache commons-collections was the LazyMap which would use a Transformer to instantiate values on the fly when doing map.get(newKey); // Will not return null!.

Why doesn't google collections have the same?

+10  A: 

Hey look! It does!

It's called new MapMaker().makeComputingMap(Function<? super K, ? extends V> computer)

Awesome.

Note that map maker is a factory - you can make one, set all the object reference types, expansion properties (and even object expiration time!), and then go about creating lots of computing maps (or other types) with one line calls.

e.g. like pretty much everything else about the google-collections library, it's really good - once you've figured out where 'it' is

Stephen
+1 to google for the "most obscure naming" award
skaffman