Map.getOrDefault(Object,Supplier<V>) override

Brian Goetz brian.goetz at oracle.com
Thu Apr 18 14:54:52 PDT 2013


BTW, another reason we are reluctant to go Supplier-happy is that there 
is a mismatch between the actual and perceived cost models for lambda 
capture.

Capturing stateless (non-capturing) lambdas is essentially free.

Capturing stateful ones, such as

   () -> state.toString()

currently has a cost comparable to instantiating an inner class instance 
that captures a local variable.  Since the only reason to provide the 
supplier version is cost, even though it may deliver significant cost 
reduction, it may not deliver as much as people expect it will.  So this 
is a small consideration in favor of not leaning on this trick too heavily.

We are looking at VM work that will significantly remove these costs, 
but first we have to get 8 out the door.


On 4/18/2013 5:32 PM, Michael Nascimento wrote:
> Hi guys,
>
> Sometimes constructing the default object is too costly and relying on
> the ternary operation is the escape hatch again. A
> Map.getOrDefault(Object,Supplier<V>) would solve this.
>
> Has this been considered before?
>
> Regards,
> Michael
>


More information about the lambda-dev mailing list