有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java为什么需要整数。价值(…)本例中的比较返回不同的值?

从a question about primitive types and autoboxing in java的答案来看:

for biziclop:

class biziclop {

public static void main(String[] args) {
    System.out.println(new Integer(5) == new Integer(5));
    System.out.println(new Integer(500) == new Integer(500));

    System.out.println(Integer.valueOf(5) == Integer.valueOf(5));
    System.out.println(Integer.valueOf(500) == Integer.valueOf(500));
}

}

Results in:

C:\Documents and Settings\glow\My Documents>java biziclop
false
false
true
false

C:\Documents and Settings\glow\My Documents>

为什么


共 (2) 个答案