JEP 302: Lambda Leftovers

Roy van Rijn roy.van.rijn at gmail.com
Thu Dec 8 08:30:59 UTC 2016


Maurizio,

> ..snip..
> so I wouldn't say it's a new issue

That is not a reason to create more of it ;-)

> - it mostly boils down to the (very subjective, I realize) perception of
> whether the lambda body provides a strong enough clue that you are inside a
> different scope. In my view, in most case this is fine - as a lambda can
> only declare local variable if it is a statement lambda with surrounding
> braces - so syntactic clues are in place.

When talking about local variables inside a lambda with braces, sure,
there is a syntactic clue in place. How many lambdas (in the wild)
actually have a lot of local variables that are now differently named
because of a collision? Is this really a problem worth solving,
risking confusion?

The JEP is talking about the following example:

Map<Integer, Integer> map = new HashMap<>();
int amount = 10;
map.computeIfAbsent(amount, amount -> amount += 10);
// What is the value of amount?

Now there is no syntactic clue to indicate a different scope. Sure, we
all know we are modifying a different 'amount' here, but will the
average Joe programmer? I'm not so sure.

Roy


More information about the platform-jep-discuss mailing list