March 2019
Intermediate to advanced
242 pages
6h 21m
English
A lambda expression that doesn't specify the types of any of its input parameters is referred to as an implicitly-typed lambda expression. In this case, the compiler infers the type of the method parameters and adds it to the bytecode.
Let's modify the lambda expression from the preceding section, dropping the types of the input parameters (the modified code is in bold):
(age) -> age > 10;
(age) -> age > 10? "Kid" : "Not a Kid";
age -> {System.out.println();};
() -> {return Math.random() + "Number";};
(name, list) -> {
return (
list.stream()
.filter(e -> e.getName().startsWith(name))
.map(Person::getAge)
.findFirst()
);
};
You can't mix implicitly-typed and explicitly-typed parameters in lambda expressions. ...
Read now
Unlock full access