In this piece of code (story * 2) == tail
is getting True
and false
for distance + 1 != tail
.
==
checks for reference , as Long is immutable , it will false for two different objects,
Here The value story * 2
is getting equal in reference to tail
, but they are two different objects and not a compile time constant for pooling.
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 no explanations for this.