March 2019
Intermediate to advanced
242 pages
6h 21m
English
Java allows for the use of the reserved word var with lambda parameters, to align its syntax with the declaration of local variables, which can now use var.
Let's modify the examples from the preceding section, adding var to the lambda parameters:
(var age) -> age > 10;
(var age) -> age > 10? "Kid" : "Not a Kid";
(var age) -> {System.out.println();}; () -> {return Math.random() + "Number";};
(var name, var list) -> {
return (
list.stream()
.filter(e -> e.getName().startsWith(name))
.map(Person::getAge)
.findFirst()
);
};
If you are using var with lambda parameters, ...
Read now
Unlock full access