March 2019
Intermediate to advanced
242 pages
6h 21m
English
A lambda expression that explicitly specifies the type of all of its input parameters is referred to as an explicitly-typed lambda expression. The following code illustrates a few examples (with the input parameters in bold):
(Integer age) -> age > 10; // input Integer, // return Boolean
(Integer age) -> age > 10? "Kid" : "Not a Kid"; // input Integer, // return String
(Integer age) -> {System.out.println();}; // input Integer, // return void
() -> {return Math.random() + "Number";}; // input none, // return String
(String name, List<Person> list) -> {
return (
list.stream()
.filter(e -> e.getName().startsWith(name))
.map(Person::getAge)
.findFirst()
);
}; // input name, // List<person> // return ...Read now
Unlock full access