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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -