当我从中读取源代码时java.io.BufferedInputStream.getInIfOpen()
,我很困惑为什么它编写了这样的代码:
/**
* Check to make sure that underlying input stream has not been
* nulled out due to close; if not return it;
*/
private InputStream getInIfOpen() throws IOException {
InputStream input = in;
if (input == null)
throw new IOException("Stream closed");
return input;
}
为什么使用别名而不是in
直接使用field变量,如下所示:
/**
* Check to make sure that underlying input stream has not been
* nulled out due to close; if not return it;
*/
private InputStream getInIfOpen() throws IOException {
if (in == null)
throw new IOException("Stream closed");
return in;
}
有人可以给出合理的解释吗?
if
声明中暂停吗?
Eclipse
,您不能在if
语句上暂停调试器。可能是该别名变量的原因。只是想把那个扔出去。我推测,当然。