Search code examples
javaternary

Ternary operator spoil OR-conditional


Execution of statement

true || true ? false : true

returns false.

Shouldn't it be true since OR conditional will not execute ternary operation (right hand side part)?


Solution

  • true || true ? false : true
    

    is the same as

    (true || true) ? false : true
    

    If you meant:

    true || (true ? false : true)
    

    then you have to add the brackets yourself.