As i understand: Conditional operators have higher presidence over Assignment operators, as the following example code shows:
public class Q10
{
public static void main(
String[] args)
{
int i = 10;
int j = 10;
boolean b = false;
if( b = i == j)
System.out.println("True");
else
System.out.println("False");
}
}
(Prints out "True")
What i cant understand is why a compliation error is not thrown at the fact a boolean variable is having an int assigned to it in the IF statement. It doesnt even look like a legal IF statemnt, but it is!
If you place the code:
b = i anywhere else, the compiler picks up this illegal assignment.
Is the assignment being ignored because the conditional side of the IF statement is the only part the compiler deals with?