gpt4 book ai didi

Java 嵌套的 if 语句与 if-else

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:04:40 24 4
gpt4 key购买 nike

<分区>

我不确定我应该更喜欢以下哪个代码片段。

A)嵌套

if(cond1 != null) {
if(cond2 != null) {
//Do the good stuff here
} else {
System.out.println("Sorry cond2 was null");
}
} else {
System.out.println("Sorry cond1 was null");
}

B)平坦

if(cond1 == null) {
System.out.println("Sorry cond1 was null");
} else if(cond2 == null) {
System.out.println("Sorry cond2 was null");
} else {
//Do the good stuff
}

我认为 B 更具可读性。但是什么更像 Java?

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