【转】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

posted @ 2022-01-13 12:26  musecho  阅读(29)  评论(0)    收藏  举报