重複の可能性:
関数の終了点が 1 つだけである必要があるのはなぜですか?
return
メソッドには、理想的には 1 つの (それ以上の)ステートメントが必要であると聞きました。それは本当です?
たとえば、どのような方法がよいでしょうか。
//1
public Object getResult() {
Object result;
if (someValue != null) { **// NOT null checking**
// initializing result
}
return result;
}
// 2
public Object getResult() {
Object result;
if (someValue == null) { // **null checking**
return null;
}
// initializing result
return result;
}