我通常与 string == null
一起测试它,所以我并不真正关心空安全测试。我应该使用哪个?
String s = /* whatever */;
...
if (s == null || "".equals(s))
{
// handle some edge case here
}
或者
if (s == null || s.isEmpty())
{
// handle some edge case here
}
关于这一点——除了 return this.equals("");
或者 return this.length() == 0;
,isEmpty()
还能做其他的事情吗?