我不明白为什么 Eclipse 会针对第二个 if 条件中的代码发出死代码警告:
boolean frameErreicht = false;
while (!frameErreicht) {
String line = reader.readLine();
if (line.matches("@\\d*")) {
reader.mark(reader.getLineNumber() - 1);
reader.setLineNumber(reader.getLineNumber() - 1);
frameErreicht = true;
}
if (line == null)
throw new IOException("Keine Angaben zu Frames im Eingabestrom");
}
LinenumberReader 的 readLine() 方法的 jdoc 说,如果到达流的末尾,它将返回 null
,因此如果在整个文本中都找不到匹配项 ( line == null
) 它应该抛出异常。
但是怎么了?
最佳答案
如果 line 为 null,line.matches("@\\d*")
将抛出 NullPointerException
关于java - 带有 2 个 if 的 while 循环中的死代码警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15231760/