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 11# java中stream使用规范
22
3- ## 1. stream中的filter表达式不要写得太长,对于复杂的表达式建议封装方法;
3+ ## stream使用规范
4+
5+ ### 1. stream中的filter表达式不要写得太长,对于复杂的表达式建议封装方法
46
57例如:
68
79``` java
810List<FlightOrder > orders = orders. stream()
9- .filter(order - > StringUtils . equals(order. status, " Submitted" )
11+ .filter(order - > StringUtils . equals(order. status, " Submitted" )
1012 && StringUtils . equals(order. paymentStatus, " Billed" )
1113 && StringUtils . equals(order. authorizeStatus, " Passed" ))
1214 .collect(Collectors . toList();
@@ -20,15 +22,15 @@ List<FlightOrder> orders = orders.stream()
2022 .collect(Collectors . toList();
2123```
2224
23- ## 2. 不要嵌套使用stream,嵌套的steam可读性很差,建议将内层的stream封装成独立的方法;
25+ ### 2. 不要嵌套使用stream,嵌套的steam可读性很差,建议将内层的stream封装成独立的方法
26+
27+ ### 3. stream要适当地换行,不要写在一行中
2428
25- ## 3. stream要适当地换行,不要写在一行中;
29+ ### 4. 不要在stream中访问数据库;
2630
27- ## 4. 不要在stream中访问数据库;
28-
2931原因: 在循环中访问数据库往往导致性能问题。
3032
31- ## 5. 不要使用stream来更新数据,只用stream来查询
33+ ### 5. 不要使用stream来更新数据,只用stream来查询
3234
3335例如:
3436
You can’t perform that action at this time.
0 commit comments