On Tue, Apr 29, 2014 at 5:43 PM, Andy Seaborne <[email protected]> wrote:
> On 29/04/14 20:29, Stephen Allen wrote: > >> One simple change I would really like to make when we switch to Java 7 is >> to make org.apache.jena.atlas.lib.Closeable extend >> java.lang.AutoCloseable. >> That way we can take advantage of try-with-resources. >> > > Which classes/patterns in particular did you want autoclosability? > org.apache.jena.atlas.lib.Closeable gets used widely. > > oaj.lib.Closeable defines close without a checked exception; > java.lang.AutoCloseable defines close to throw an exception: > > I want all of them to implement AutoCloseable. Then the user can use try-with-resources on any of our oaj.lib.Closeable classes. We would have oaj.lib.Closeable extend java.lang.AutoCloseable and override the close() method to throw no exception. That doesn't break any legacy interaction, but adds the try-with-resources feature if you want it. See the last section of [1] that describes this behavior. -Stephen [1] http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
