【转】Java中的Optional
https://www.cnblogs.com/zhangboyu/p/7580262.html
原来
if (ciDto.getId() != null) {
this.key = ciDto.getId();
}
可以改为:
Optional.ofNullable(ciDto.getId()).ifPresent(s -> this.key = s);
当ciDto.getId()不为null时,执行函数this.key = s
https://www.cnblogs.com/zhangboyu/p/7580262.html
原来
if (ciDto.getId() != null) {
this.key = ciDto.getId();
}
可以改为:
Optional.ofNullable(ciDto.getId()).ifPresent(s -> this.key = s);
当ciDto.getId()不为null时,执行函数this.key = s