java - Checking all conditions in a logical disjunction -


i found question in line of code. ignore fact code not make sense:

if (object != null || object.somemethod()) object.dosomething(); 

first thinking code throw nullpointerexception if object null. but, logical disjunction , if 1 of conditions true whole condition true. compiler doesn't checks second condition , doesn't throws nullpointerexception.

is java standard behavior or implementation specific? if second case true code not secure.

when object not null, short-circuit evaluation occurs, , object.somemethod() never called.

when object null, expression should throw nullpointerexception when object.somemethod() evaluated.

this not particularly useful condition. consider whether && intended instead of ||.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -