Bitten by the lambda parameter name

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Jul 16 08:30:29 PDT 2013


On 16/07/13 16:20, Remi Forax wrote:
> computeIfAbsent, put the computed value in the Map if the couple 
> key/value doesn't exist,
> thus computeIfAbsent is useful when using a Map as a cache.
> The method that provide a default value is getOrDefault and yes, it's 
> often better to send the default value when creating the Map,
> because the default value usually doesn't change but at the same time, 
> storing a default value like Collections.emptySet() in each map is not 
> very memory efficient. 
Well, the lambda is there exactly for that reason - I believe, so that 
default values are created lazily. What I was saying is - any reason as 
to why the lambda shouldn't be passed to the Map constructor, rather 
than to the get method?

Maurizio


More information about the lambda-dev mailing list