posted by
jbanana at 05:49pm on 15/03/2021
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
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 closedBut today I found that it works for something you already opened!
Reader r = new FileReader(/*blah*/); try(r){ r.whatever(); } // r is automatically closedThis 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.)