私は次のようなコードを持っています:
obj1 = SomeObject.method1();
if (obj1 != null) {
obj2 = obj1.method2();
if (obj2 != null) {
obj3 = obj2.method3();
if (obj3 != null) {
............
return objN.methodM();
}
}
}
....
10段近くあります。非常に壊れやすく、エラーが発生しやすいようです。null チェーン メソッドをチェックするより良い方法はありますか?
ありがとう。