gpt4 book ai didi

java - orElseThrow 是否比 if(obj == null) 更好?

转载 作者:行者123 更新时间:2023-11-30 07:47:11 25 4
gpt4 key购买 nike

<分区>

我有一个问题。

这是吗

Issue issue = Optional.ofNullable(someMethod())
.orElseThrow(() -> new Exception("Issue is null"));

比这更好

Issue issue = someMethod();
if (issue == null) {
throw new Exception("Issue is null");
}

?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com