Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Features new in Java 7 and the fly likes try-with-resources Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "try-with-resources" Watch "try-with-resources" New topic


Rick Goff
Ranch Hand

Joined: Nov 14, 2006
Posts: 54

What are the best practices emerging for implementation/refactoring related to try-with-resources?

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46320
If you have something predating try-with-resources, you should be instantiating the IfItAintBrokeDontFixIt class
Richard Reese
Ranch Hand

Joined: Jul 13, 2011
Posts: 84

I concur with Ritchie's answer. However, for the applications that uses try block and are in need of re-writing the try-with-resources block is the way to go. NetBeans 7.1.1 apparently has a tool that will assist in the conversion of an older application to Java 7, including try-with-resources conversion. I haven't used it but it is discussed at

Richard Reese
Java 8 New Features: A Practical Heads-Up Guide
I agree. Here's the link:
subject: try-with-resources
jQuery in Action, 3rd edition