In this code snippet (story * 2) == tail , True
and false for distance + 1 != tail .
== checks for links, since Long is immutable, it will be false for two different objects,
Here, the value of story * 2 becomes equal with respect to tail , but these are two different objects, not a compile-time constant for the union.
public class Test2 { public static void main(String [] args) { Long tail = 2000L; Long distance = 1999L; Long story = 1000L; System.out.println(tail > distance); System.out.println((story * 2) == tail); if((tail > distance) ^ ((story * 2) == tail)) System.out.print("1"); System.out.println(distance + 1 != tail); System.out.println((story * 2) == distance); if((distance + 1 != tail) ^ ((story * 2) == distance)) System.out.print("2"); }
I checked here , but there was no explanation for this.
source share