String.contains(null)留神了
引言:
今天同事发现我封装的SQL分离,有个很2B的异常——“NullPointerException”。丢人丢大发了,留个爪印,以后用新方法得先留神说明书了~。=
正文:
直接上测试代码:
/** * Returns true if and only if this string contains the specified * sequence of char values. * * @param s the sequence to search for * @return true if this string contains <code>s</code>, false otherwise * @throws NullPointerException if <code>s</code> is <code>null</code> * @since 1.5 */ public boolean contains(CharSequence s) { return indexOf(s.toString()) > -1; }
注释上已经说明用法了。就不再浪费大伙带宽了~~。+
1 楼 yuhui0531 2012-03-06 果然2,非常2,相当2,十分2,真是2B 2 楼 zhaoningbo 2012-03-06 yuhui0531 写道果然2,非常2,相当2,十分2,真是2B
哈哈~~~ 恩恩,引以为戒 3 楼 Mybeautiful 2012-03-07 如果你不了解这个新方法,又不想花时间深入了解。就默认它没有做null处理.. 4 楼 yuhui0531 2012-03-08 zhaoningbo 写道yuhui0531 写道果然2,非常2,相当2,十分2,真是2B
哈哈~~~ 恩恩,引以为戒
哈哈,和你开玩笑呢。。
其实我也不晓得。