The compiler doesn't change the branch logic. It's the compiler's natural behavior to use if_icmpne in this case (just my opinion) To make (eclipse) compiler use if_icmpeq
, just change your code as following:
if (x != y) {
AircraftControl.readSensor(x);
}
else {
AircraftControl.readSensor(y);
}
This code:
public static void main(String[] args) {
int x = (int) System.currentTimeMillis(), y = (int) System
.currentTimeMillis();
if (x != y) {
System.out.println("x != y");
} else {
System.out.println("x == y");
}
}
Result in:
0: invokestatic #16 // Method java/lang/System.currentTimeMillis:()J
3: l2i
4: istore_1
5: invokestatic #16 // Method java/lang/System.currentTimeMillis:()J
8: l2i
9: istore_2
10: iload_1
11: iload_2
12: if_icmpeq 26
15: getstatic #22 // Field java/lang/System.out:Ljava/io/PrintStream;
18: ldc #26 // String x != y
20: invokevirtual #28 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
23: goto 34
26: getstatic #22 // Field java/lang/System.out:Ljava/io/PrintStream;
29: ldc #34 // String x == y
31: invokevirtual #28 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
34: return