文选流氓 发表于 2003-2-7 01:33

1-1-19-23 请问null和""有什么差别?

发信人: flyyi (伊烟), 信区: Java      
标题: Re: 请问null和""有什么差别?
发信站: BBS 水木清华站 (Tue Jul 23 20:07:30 2002)

《effective java》。
null表示不存在对对象的引用,而""表示空字符串,存在引用,也就是说存在指向""的“
指针”。
String中的equals()方法似乎不能用null作为参数。这是jdk1.3doc 的内容:

public boolean equals(Object anObject)Compares this string to the specified ob
ject. The result is true if and only if the argument is not null and is a Stri
ng object that represents the same sequence of characters as this object.

应该用!=来比较。
【 在 tainy 的大作中提到: 】
: 哦?请指教
: 我记得那本著名的effective java programming(似乎是这个名字)
: 里面不推荐用捕获异常代替逻辑流程。
: 再说,上面的用法我也没发现多此一举啊,请说明一下好吗?呵呵
: 【 在 ooww (白皮) 的大作中提到: 】
: : 但似乎这是推荐的做法啊
: : 而且这里判断多此一举啊
页: [1]
查看完整版本: 1-1-19-23 请问null和""有什么差别?