java - java 8中lamda表达式的使用
问题描述
我想重构这段代码以使用 lambda 表达式 java 8
for(int i = 0; i < customers.getCUSTOMER().size(); i++){
if (customers.getCUSTOMER().get(i).getINCOME().getGROSSMONTH1().toBigInteger()
< customers.getCUSTOMER().get(i).getINCOME().getNETTSALMONTH1().toBigInteger()){
log.error("")
throw new RuntimeException();
}
}
解决方案
customers.getCUSTOMER().stream().forEach(customer -> {
if(customer.getINCOME().getGROSSMONTH1().toBigInteger() < customer.getINCOME().getNETTSALMONTH1().toBigInteger()){
log.error("");
throw new RuntimeException();
}
});
您还应该尝试使用驼峰命名法重命名您的方法,例如 getIncome() 以使其更易于阅读并符合正常的 Java 编写标准。
推荐阅读
- java - 检查 Null 并将两个字符串与 Java 中的分隔符组合,否则返回一个 [Java -7]
- mysql - 为什么 HAVING MAX() 返回的值与 SELECT MAX() 不同?
- jquery - jQuery数据表分页 - 在多个页面上发送表单的问题
- java - tableModel.addRow() 未在 JTable 中显示任何内容,但行对象具有值
- java - java - 如何在spring boot java中编写一个函数来处理JPA存储库中的自定义查询?
- batch-file - Windows 批处理等效于 linux 剪切、粘贴和管道到文件
- python - PyQT 点击事件仅在开始时执行,并且不再起作用
- android - Android Studio 没有为我设置
- c# - 如何使用 Emgu.CV 将小图像复制到大图像中的指定位置?
- r - 带有marrangeGrob的ggplot列表,错误地绘制相同的