在使用String类的replaceAll API时,我遇到了Null Pointer Exception.
然后我尝试用下面粘贴的小片段,我正在接受NPE.
String s = "HELLO @WORLD@ I AM.";
System.out.println(s.replaceAll("@WORLD@", null)) ;
Run Code Online (Sandbox Code Playgroud)
我也发现在String.java类中
public Matcher appendReplacement(StringBuffer sb, String replacement) {
.......//code
while (cursor < replacement.length()) { ..//code}
.......//code
}
Run Code Online (Sandbox Code Playgroud)
所以这里它称之为replacement.length()NPE的原因.
是否有规则我们不能将第二个参数作为null传递?
我知道如果替换单词为null,JVM将替换什么.
| 归档时间: |
|
| 查看次数: |
6253 次 |
| 最近记录: |