I was reading through some old code and came across an unqualified Boolean expression like this:
if (first && second || third)
{
// do something
}
There are two valid ways of qualifying that expression.
if ((first && second) || third)
and
if (first && (second || third))
which evaluate differently for some values of first, second and third.
I tried this out in C# and the results aligned with the first qualification method. Curiosity got the better of me and I tried it out in Java too, which aligned with the second method. Why is this? Shouldn't the evaluation be the same in different languages?