I have a long chain of objects and want to check if the last object in the chain is null. Like this:
if(obj1.obj2.obj3.obj4) {
// obj4 is not null --> do stuff
}
However if obj3 is null, I get an exception. So I would have to do:
if(obj1.obj2.obj3) {
// obj3 is not null
if(obj1.obj2.obj3.obj4) {
// obj4 is not null --> do stuff
}
}
obj1 and obj2 might be also null, so I have to check these as well. I'm sure there must be a better way to implement this, instead of doing if-chains.