mardi 19 décembre 2017

Java: Short-circuting && after OR

I understand && and || are short circuited in Java (whereas & and | are not)

However, I do not understand why the following code (which starts off with short circuited OR but ends with && condition) is also short circuited:

String x, y;
if ( x.contains("this") || x.contains("that") && y.contains("something else")!= true)

I would think that even if condition x.contains("this") evaluates to true the program will still need to evaluate the last condition y.contains("something else") != true because there's the && operator before the last condition. But apparently this isn't the case.

Can anyone explain why?

Aucun commentaire:

Enregistrer un commentaire