今天做了一个试验:new Long(32).equals(new Long(32))。
这个表达式的返回值是false。为什么呢?这是JDK文档中的描述:
Compares this object to the specified object. The result is true if and only if the argument is not null and is a Long object that contains the same long value as this object.
是我做错了什么地方?还是JDK的问题?
[code="java"]public class Test {
/**
*
* @param args
*/
public static void main(String[] args) {
System.out.println(new Long(32).equals(new Long(32)));//true
}
}
[/code]
可能和jdk有关系吧.我这里比较的结果是 true
这个一定是返回true的嘛,
除非你用==的话,就返回false