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

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -