null
在调用close()
开放资源之前,网上有一些例子。
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?
}