What happens with operators like < > == != etc is that their argument types and types are different.
Let’s see if I can explain it simply. Let’s look at some ordinary arithmetic operators. 1 + 2. Keep it nice and simple
1 is an int
2 is an int
+ can take two ints
+ on two ints has the type int.
So 1 + 2 as a whole expression is an int.
Now try 1 + 2 + 3.
The JVM evaluates that expression from left to right, and the operator priorities are consistent with ordinary arithmetic. So, what stage are we at halfway through the evaluation?
(1+2allDoneAndEvaluated) + 3
Now we know that 3 is an int, and we have already seen that (1+2allDoneEtc) is also an int. So we are supplying the + operator with two ints, and the compiler is happy.
What about != ? It can take two ints, but it returns a boolean. So if you try i != j != k, you get this sort of thing, assuming i j and k are all ints.
i is an int
j is an int
!= can take two ints
!= on two ints has the type boolean [First difference from 1 + 2]
Evaluating from left to right, exactly as before.
(i!=jAllDoneEtc) != k
(i!=jAllDoneEtc) has the type boolean, and k has the type int.
The != operator cannot cope with mixed types (boolean != int) like that. So the compiler will complain. You probably get an error message like “expected boolean found int”.
Damn! I have answered the wrong question.
Well, you can have the answer anyway. It matches the original question better.