Content deleted Content added
m add missing reference-list |
→Language constructs: add Java "try-with-resources" reference link |
||
Line 28:
To make the dispose pattern less verbose, several languages have some kind of built-in support for it:
The [[C Sharp (programming language)|C#]] language features the <code>using</code> statement <ref>Microsoft MSDN: [http://msdn.microsoft.com/en-us/library/yh598w02.aspx using Statement (C# Reference)]</ref> that automatically calls the <code>Dispose</code> method on an object that implements the <code>IDisposable</code> [[interface (computer science)|interface]]:
<source lang="csharp">
Line 59:
</source>
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(...) ){
|