ここにサンプルコードがあります。関数によって作成されたFileInputStreamは、コードがparentFunctionのtry/catchブロックが存在するときに自動的に閉じられますか?Java自動クローズ機能の動作
someOtherFunction()自体で明示的に閉じておく必要がありますか?
private void parentFunction() {
try {
someOtherFunction();
} catch (Exception ex) {
// do something here
}
}
private void someOtherFunction() {
FileInputStream stream = new FileInputStream(currentFile.toFile());
// do something with the stream.
// return, without closing the stream here
return ;
}
あなたがしよう、と '[のリソースを指定する必要があるだろう-resources'](https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html)ステートメントを自動的にクローズする –