-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava8.java
More file actions
34 lines (27 loc) · 818 Bytes
/
java8.java
File metadata and controls
34 lines (27 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(params) -> expression
(params) -> statement
(params) -> { statements }
Map
IntStream.iterate(1, i -> i + 2); // Infinite iterator
IntStream.iterate(0, i -> i + 2).limit(10).forEach(System.out::println);
int sum = IntStream.of(a).sum();
List<String> features = ...
features.forEach(n -> System.out.println(n));
features.forEach(System.out::println);
// Design Patterns in the Light of Lambda Expressions by Subramaniam
// Execute Around Method Pattern
class Resource {
private Resource() {}
public Resource op1() {return this;}
public Resource op2() {return this;}
private void close() {}
public static void use(Consumer<Resource> block) {
Resource resource = new Resource();
try {
block.accept(resource);
} finally {
resource.close();
}
}
}
Resource.use(resource -> resource.op1().op2());