Reputation: 378
Does implicit finally block exist for all try statements (try, try-finally, try-catch-finally) or only for try-with-resources?
Upvotes: 1
Views: 123
Reputation: 96394
No. The closest thing i can think of like "implicit closing functionality" is finalization: Some classes may have a finalize method implemented that executes at some later time, whenever the object is garbage collected. That would have to have the close method called so not sure implicit is the right word. There was no Closeable interface to indicate things that needed closing before 1.7 and try-with-resources, there was no interface you could tag a class with to tell the jvm it needed closing. And that has nothing to do with any kind of try block.
The try block came first and is entirely explicit. Try-with-resources came along later, it addresses exception masking issues that can happen when using try-finally blocks. This is my explanation of why try-with-resources was created.
Upvotes: 1