Bitten by the lambda parameter name
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Tue Jul 16 08:05:47 PDT 2013
On 16/07/13 16:00, Peter Levart wrote:
> Perhaps here, an overloaded Map.computeIfAbsent that takes a Supplier
> instead of Function would be handy. Even when you need the key to
> construct new value, it is usually ready in some effectively-final
> variable in the scope. And when you don't need the key, a constructor
> reference could be applied like:
>
> partySetMap.computeIfAbsent(kind, HashSet::new).add(...);
+1
I think the underlying problem to this discussion might be that there
are places (and computeIfAbsent seems to be one of them) where the
lambdi-fication of the library took a somewhat convoluted path, in which
the 'same' variables needs to be supplied multiple times in order to
keep the chain happy (which then turns out to be problematic because of
scoping rules).
In my eyes, computeIfAbsent also looks a bit off - i.e. wouldn't it be
useful to provide an option to fill in default values for absent keys at
map construction rather than at call site?
Maurizio
More information about the lambda-dev
mailing list