JEP 302: Lambda Leftovers

Roy van Rijn roy.van.rijn at gmail.com
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?

Roy

> Op 7 dec. 2016 om 00:50 heeft mark.reinhold at oracle.com het volgende geschreven:
> 
> New JEP Candidate: http://openjdk.java.net/jeps/302
> 
> - Mark


More information about the platform-jep-discuss mailing list