Dispose pattern: Difference between revisions

Content deleted Content added
Line 131:
The [[Java (programming language)|Java]] language introduced a new syntax called <code>try</code>-with-resources in Java version 7.<ref>Oracle Java tutorial: [http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html The try-with-resources Statement]</ref> It can be used on objects that implement the AutoCloseable interface (that defines method close()):
<source lang="java">
try ( OutputStream x = new OutputStream(...) ) {
//do Do something with x
} catch (IOException ex) {
//handle Handle exception
 
// The resource x is automatically closed