March 2019
Intermediate to advanced
242 pages
6h 21m
English
When you write a lambda expression, you (usually) define the parameter names as indicators of how the values assigned to them should be processed. They aren't meant to reuse the existing values, referred to by variables, in an enclosing block.
Let's revisit the preceding code:
1. String key = "Docker"; // local variable key2. talks.stream()3. .map(key -> key.toUpperCase()) // WON'T compile : 'key' // redefined4. .forEach(System.out::println);
In the preceding code, the lambda expression on line 3 (in bold) defines one lambda parameter, key, specifying that when a value is passed to it, Java should call the toUpperCase() method on it and return the resulting value.
As is evident ...
Read now
Unlock full access