使用Stream流出现空指针异常

只有在编译的时候才会报错很容易忽视

样例

List<RecTypeDictEntity> recTypeDictList=recTypeDictEntities.stream().filter(i->i.getRecTypeCode().equals(docitemecode)).collect(Collectors.toList());

看起来好像没什么问题,但是实际上一运行就报错,因为没有对list中的对象属性判断是否为空,直接使用就会出现空指针异常问题

改进


List<RecTypeDictEntity> recTypeDictList=recTypeDictEntities.stream().filter(i->StrUtil.isNotBlank(i.getRecTypeCode())&&i.getRecTypeCode().equals(docitemecode)).collect(Collectors.toList());
posted @ 2023-05-31 15:36  haowe  阅读(729)  评论(0)    收藏  举报