Java 8 Lambda Stream forEach with multiple statements

前端 未结 4 933
心在旅途
心在旅途 2021-02-01 12:44

I am still in the process of learning Lambda, please excuse me If I am doing something wrong

final Long tempId = 12345L;
List updatedEntries = new L         


        
4条回答
  •  误落风尘
    2021-02-01 13:31

    You don't have to cram multiple operations into one stream/lambda. Consider separating them into 2 statements (using static import of toList()):

    entryList.forEach(e->e.setTempId(tempId));
    
    List updatedEntries = entryList.stream()
      .map(e->entityManager.update(entry, entry.getId()))
      .collect(toList());
    

提交回复
热议问题