posted by
jbanana at 05:49pm on 15/03/2021
You've been able to can auto-close a closable thing for ages now.
try(Reader r = new FileReader(/*blah*/)){
r.whatever();
}
// r is automatically closed But today I found that it works for something you already opened! Reader r = new FileReader(/*blah*/);
try(r){
r.whatever();
}
// r is automatically closed This came up because I had a list of files and I wanted to close each one after handling it. So I couldn't create it in the header of the try block.
There are no comments on this entry. (Reply.)