forked from hellokaton/write-readable-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample1.java
More file actions
37 lines (30 loc) · 788 Bytes
/
Copy pathExample1.java
File metadata and controls
37 lines (30 loc) · 788 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
35
36
37
package chapter_10;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiConsumer;
/**
* 减少变量
*
* @author biezhi
* @date 2018/7/21
*/
public class Example1 {
class Message {
LocalDateTime lastViewTime;
}
public void part1(Message rootMessage) {
rootMessage.lastViewTime = LocalDateTime.now();
}
public void part2() {
BiConsumer<List<Integer>, Integer> consumer = (array, valueToRemove) -> {
for (int i = 0; i < array.size(); i++) {
if (array.get(i).equals(valueToRemove)) {
array.remove(i);
break;
}
}
};
consumer.accept(Arrays.asList(1, 2, 3), 2);
}
}