Java 7 try-with-resources

About Jamie Craane

Java 7 provides better resource management for resources that need to be closed when finished working with, for example files, streams, database connection and sockets. This language construct is called the try-with-resources statement. The mechanism that makes this work is called the AutoCloseable interface. The Java 7 resource classes all implement this interface. The signature of this interface looks like this:
 
 
 
 
 

public interface AutoCloseable {    void close() throws Exception;}

It declares one method, close(), which is automatically invoked on objects managed by the try-with-resources statement.


Source : http://www.javacodegeeks.com/2013/07/java-7-try-with-resources.html

Back to Top