Hi,
I am having trouble understanding what happens when short-circuit operators and bitwise operators are combined in an expression producing a boolean result. The following code has both a && operator and a | operator.
I thought that the following code would update the count variable to 1, because the ba.b[++ba.count] | true would be first evaluated because " | " holds higher order of precedence than " && ". However, I found out that it does not evaluate that all, and short-circuits, with the count variable not being updated.
public class BoolArray {
boolean [] b = new boolean[3];
int count = 0;
public static void main(
String[] args) {
BoolArray ba = new BoolArray();
ba.b[0] = false;
ba.b[1] = false;
ba.b[2] = false;
if (false && ba.b[++ba.count] | true) {
System.out.println("We are here");
}
System.out.println(ba.count);
Thanks
Vinal.