【发布时间】:2016-07-13 20:45:48
【问题描述】:
当我阅读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,如下所示:
/**
* 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;
}
谁能给个合理的解释?
【问题讨论】:
-
在
Eclipse中,您不能在if语句上暂停调试器。 可能是该别名变量的原因。只是想把它扔出去。当然,我推测。 -
@DebosmitRay : 真的不能暂停
if声明? -
@rkosegi 在我的 Eclipse 版本上,问题类似于this one。可能不是很常见的情况。无论如何,我的意思并不是轻描淡写(显然是个坏笑话)。 :)