Анонимна функция: Разлика между версии

Изтрито е съдържание Добавено е съдържание
Редакция без резюме
м без интервал
Ред 39:
 
// with a code block
(a, b) -> { return a + b; }
 
// with multiple statements in the lambda body. It requires a code block.
// This example also includes two nested lambda expressions (the first one is also a closure).
(id, defaultPrice) -> {
Optional<Product> product = productList.stream().filter(p -> p.getId() == id).findFirst();
return product.map(p -> p.getPrice()).orElse(defaultPrice);