Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // with no parameter
- () -> System.out.println("Hello, world.")
- // with a single parameter (This example is an identity function).
- a -> a
- // with a single expression
- (a, b) -> a + b
- // with explicit type information
- (long id, String name) -> "id: " + id + ", name:" + name
- // 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);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement