Error:
operator && cannot be applied to boolean, <data type>
or
operator || cannot be applied to boolean, <data type>
Explanation:
The compiler has found a boolean operator being used with an operand that does not evaluate to true or false.
Checklist:
- Is an if or while condition using the either the AND (&&) operator or the OR (||) operator with integer or floating-point operands?
Example:
With the following statements in a source file named Compare.java:
11 int x = 1, y = 2, z = 1;
12 if ( x == y && z ) // Note: z is an int, not a boolean value
13 System.out.println( "x, y and z are equal" );
the Java compiler would generate the following error:
Compare.java:12: operator && cannot be applied to boolean, int
if ( x == y && z )
^
To fix the problem, change line 12 to:
if ( x == y && x == z ) both operands evaluate to true or false