Qian Xu schrieb: ----------- code 2 (current solution) -------------- > > public test(MyObj obj) > { > if (obj !is null && > obj.getObj2 !is null && > obj.getObj2.getObj3 !is null) > { > obj.getObj2.getObj3.test(); > } > } > > ------------------------------------------------------
If you want to be able to return something like "nothing", you can use NullObject. That is, return an object that lets you navigate the references and lets you test for it being a "null" object. auto o = obj.getObj2.getObj3; if( !o.isNull() ){ o.test(); }