Yes that is correct and but still i had confusion that why it is giving error.
I knew rule precedence all the Boolean operator has less precedence over arithmetic operator.
But i was just missing line which should explain me why it is throwing error.
And now i understand.
Since + operator has more precedence over | there for it will became like true|"falsehello" and since | operator work if both operand boolean and in this case it is not
that is reason why it is throwing exception.
Thanks for replay which force me to rethink and now i understand fully. i got missing link.
true | now looks at right side is there higher precedence operator than | answer is yes i.e. + additive operator so goes to +
true | ( false + "hello") does conversion of boolean to Boolean and then that Boolean reference to String then does String concatination results "falsehello".
true | ("falsehello") now you can see | the bitwise and logical operators may be used to compare two operands of numeric type or two operands of type boolean. All other cases result in a compile-time error so | operator can't be applied to boolean and String.
so you get that error.
Try doing this see what you get
prateek shaw wrote:. . . that is reason why it is throwing exception. . . .
I hope you are not having an exception thrown; Junilu and Ganish have explained why that code will not even compile. A compile‑time error is different from an exception.
One way to make it compile is to add ():-
... (true | false) + " hello" ... That will evaluate to