This is because of the way expression and types are evaluated.
Let's evaluate the leftmost ==
x == y ...
This evaluates to true. Let's rewrite the expression:
// x == y
if (true == z) {
// ...
}
The true
is a boolean value. A boolean value cannot be directly compared to an int
. A conversion from the boolean to an integer must occur, and the result is 1
(yes, true
== 1
). Let's rewrite the expression to its equivalent value:
// true
if (1 == z) {
// ^--- that's false
}
But z
isn't equal to 1
. That expression is false!
Instead, you should separate both boolean expressions:
if (x == y && y == z) {
// ...
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…