【发布时间】:2019-01-22 11:37:15
【问题描述】:
我想更新一个条目如下:
public Entry updateEmail(String nom, EntryRequest entryReq) {
Optional<Entry> optional = entryRepository.findByNom(nom);
Entry updatedEntry = null;
optional.ifPresent(entry -> {
if(!StringUtils.isEmpty(entryReq.getEmail())){
entry.setEmail(entryReq.getEmail());
}
updatedEntry = save(entry);
});
optional.orElseThrow(() -> new NotFoundException(this.getClass().getName()));
return updatedEntry;
}
这段代码给了我以下错误信息:
lambda 表达式中使用的变量应该是最终的或有效的 最终
我该如何解决这个问题?
【问题讨论】: