JEP 302: Lambda Leftovers

Roy van Rijn roy.van.rijn at
Wed Dec 7 21:01:52 UTC 2016

The only thing about 300, 301 and 302 I don't like initially is the possible danger that could come from shadowing. Not just the fear of loss of readability.

For example the following code:

Map<String, Integer> map = ...
String key = "theInitialKey";

map.computeIfAbsent(key, _ -> {
   String key = "theShadowKey"; // <- delete this
   return key.length();

If you delete that line... nothing fails. The code runs fine, but the behavior has changed, suddenly a different 'key' is used. That is a hidden danger of shadowing. I want my code to break if declarations are removed. There should not be fallbacks to different variables?


> Op 7 dec. 2016 om 00:50 heeft mark.reinhold at het volgende geschreven:
> New JEP Candidate:
> - Mark

More information about the platform-jep-discuss mailing list