<分区>
我不确定我应该更喜欢以下哪个代码片段。
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?