【发布时间】:2015-11-03 21:15:41
【问题描述】:
我创建了一个包含以下字段的 Interval 类:
...
private static final Integer MINF = Integer.MIN_VALUE;
Integer head,tail;
...
当我创建这个类的一个实例时,创建this.head = Integer.MIN_VALUE,并且我想检查head 的值是否等于MINF,它说它们不相等。
Interval i = new Interval(Integer.MIN_VALUE,10);
System.out.println(i.toString()); //[-2147483648,10]
所以我继续尝试打印值,
public String toString() {
...
//What the hell?
System.out.println("MINF == Integer.MIN_VALUE: " + (MINF == Integer.MIN_VALUE)); //true
System.out.println("MINF == this.head: " + (MINF == this.head)); //false
System.out.println("Integer.MIN_VALUE == this.head: " + (Integer.MIN_VALUE == this.head)); //true
...
return "*insert interval in format*";
}
这说的是
MINF == Integer.MIN_VALUE 是真
MINF == this.head 是 false,虽然 this.head = -2147483648
Integer.MIN_VALUE == this.head 是真
我是否遗漏了什么,为什么第二个是假的?
【问题讨论】: