coding style - Is there a simpler way to derefence nullable references in Java? -


consider following code snippet:

if (foo != null  && foo.bar != null  && foo.bar.boo != null  && foo.bar.boo.far != null) {     dosomething (foo.bar.boo.far); } 

my question simple: there more simple\shorter way ?

in detail: there more simple way validate each part of chain, i'd imagine similar ..

if (validate("foo.bar.boo.far")) {     dosomething (foo.bar.boo.far); } 

maybe ?

if (fooutils.isfarnotempty(foo)){     dosomething (foo.bar.boo.far); } 

and in fooutils :

boolean isfarnotempty (foo foo){    return foo != null &&            foo.bar != null &&            foo.bar.boo != null &&            foo.bar.boo.far != null; } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -