为什么当参数 obj 为 null 时 String.valueOf(Object obj) == null return false?
Why does String.valueOf(Object obj) == null return false when argument obj is null?
public static void main(String[] args) {
Long lo = null;
System.out.println(String.valueOf(lo) == null);
}
为什么上面的说法return是错误的?
谁能解释一下..
阅读 Javadoc:
Returns:
if the argument is null
, then a string equal to "null"
; otherwise, the value of obj.toString()
is returned.
换句话说,结果是 string "null"
,而不是 value null
。
public static void main(String[] args) {
Long lo = null;
System.out.println(String.valueOf(lo) == null);
}
为什么上面的说法return是错误的? 谁能解释一下..
阅读 Javadoc:
Returns:
if the argument is
null
, then a string equal to"null"
; otherwise, the value ofobj.toString()
is returned.
换句话说,结果是 string "null"
,而不是 value null
。