標(biāo)題基本上說明了一切。我通常會(huì)在的同時(shí)進(jìn)行測試string == null,因此我并不真正擔(dān)心null安全測試。我應(yīng)該使用哪個(gè)?String s = /* whatever */;...if (s == null || "".equals(s)){ // handle some edge case here}要么if (s == null || s.isEmpty()){ // handle some edge case here}關(guān)于這一點(diǎn)-它isEmpty()甚至做得比其他任何事情return this.equals("");或return this.length() == 0;?
我應(yīng)該使用string.isEmpty()還是“” .equals(string)?
哆啦的時(shí)光機(jī)
2019-10-25 10:42:42