A few of the known issues

As of now, it isn't clear whether a lambda expression will be able to access the value of the enclosing variable, which is overshadowed by the lambda parameter; and if it can, how?

For example, let's modify the preceding code by replacing the call to the toUppercase() method with a call to the concat() method as follows (changes are in bold):

1. String key = "Docker"; // local variable key
2. talks.stream()
3. .map(key -> key.concat(key))
4. .forEach(System.out::prinltn);

In the preceding code, imagine that the lambda expression on line 3 needs to access the value of the key variable defined on line 1, since it wants to pass it to the concat() method. As of right now, it hasn't been finalized whether this will be allowed.

If it is allowed, Java will need to devise a way to mark and clearly differentiate a lambda parameter from another variable with the same name, in the enclosing block. This will be required for code readability—which, as you know, is important.

The accessibility of the overshadowed enclosing variable is the main problem associated with shadowing of lambda parameters.

In the next section, we'll look at how Java is trying to resolve overloaded method calls, which define functional interfaces as parameters.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.22.179