File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 1
1
# java中stream使用规范
2
2
3
- ## 1. stream中的filter表达式不要写得太长,对于复杂的表达式建议封装方法;
3
+ ## stream使用规范
4
+
5
+ ### 1. stream中的filter表达式不要写得太长,对于复杂的表达式建议封装方法
4
6
5
7
例如:
6
8
7
9
``` java
8
10
List<FlightOrder > orders = orders. stream()
9
- .filter(order - > StringUtils . equals(order. status, " Submitted" )
11
+ .filter(order - > StringUtils . equals(order. status, " Submitted" )
10
12
&& StringUtils . equals(order. paymentStatus, " Billed" )
11
13
&& StringUtils . equals(order. authorizeStatus, " Passed" ))
12
14
.collect(Collectors . toList();
@@ -20,15 +22,15 @@ List<FlightOrder> orders = orders.stream()
20
22
.collect(Collectors . toList();
21
23
```
22
24
23
- ## 2. 不要嵌套使用stream,嵌套的steam可读性很差,建议将内层的stream封装成独立的方法;
25
+ ### 2. 不要嵌套使用stream,嵌套的steam可读性很差,建议将内层的stream封装成独立的方法
26
+
27
+ ### 3. stream要适当地换行,不要写在一行中
24
28
25
- ## 3. stream要适当地换行,不要写在一行中;
29
+ ### 4. 不要在stream中访问数据库;
26
30
27
- ## 4. 不要在stream中访问数据库;
28
-
29
31
原因: 在循环中访问数据库往往导致性能问题。
30
32
31
- ## 5. 不要使用stream来更新数据,只用stream来查询
33
+ ### 5. 不要使用stream来更新数据,只用stream来查询
32
34
33
35
例如:
34
36
You can’t perform that action at this time.
0 commit comments