Map.getOrDefault(Object,Supplier) override (original) (raw)

John Rose john.r.rose at oracle.com
Thu Apr 18 19:06:41 PDT 2013


On Apr 18, 2013, at 6:56 PM, Jed Wesley-Smith <jed at wesleysmith.io> wrote:

myMap.getAsOptional(myKey).map((Map.Entry<K, V> e) -> e.getValue()).orElse(() -> z)

I also considered Map.getEntryAsOptional: Since (hypothetical) getEntry cannot return null, Optional is good.

But the use cases are verbose, partly because you need to declare a temp of type Optional<Entry<K,V>>. And/or you need some funky methods on Optional (as above). (New default methods on Entry won't seem to help, alas.) Either way the use cases are not very ... usable.

— John



More information about the lambda-dev mailing list