Is there a difference between using a logical operator or a bitwise operator in an if block in Java?

前端 未结 5 2096
长发绾君心
长发绾君心 2020-12-24 10:28

The contents of both of the following if blocks should be executed:

if( booleanFunction() || otherBooleanFunction() ) {...}
if( booleanFunction() | otherBool         


        
5条回答
  •  执笔经年
    2020-12-24 10:44

    if( booleanFunction() || otherBooleanFunction() ) {...}
    

    In this condition if booleanFunction() returns true then otherBooleanFunction() would not be executed.

    if( booleanFunction() | otherBooleanFunction() ) {...}
    

    But in bitwise operator both functions - booleanFunction() and otherBooleanFunction() would be executed no matter booleanFunction() returns true or false

提交回复
热议问题