有在網絡上調用close()
開放資源之前檢查null
例子檢查。空與傳統finally塊用於關閉資源
final InputStream in = ...; // may throw IOException
try {
// do something.
} finally {
if (in != null) { // this is really required?
in.close();
}
}
我一直都沒有做過null-checking-if
。
final InputStream in = ...; // may throw IOException
try { // when it reached to this line 'in' is never null, could it be?
// do something.
} finally {
in.close(); // no null check required, am i wrong?
}
如果你要「趕上」IOException,你應該把這個任務放在一個'try'塊中,不是嗎? – 2013-05-06 01:32:53
@JinKwon什麼用的意思'...',它只是短打字或者是它在Java – 2017-01-17 12:36:46