aboutsummaryrefslogtreecommitdiff
path: root/website
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-07-18 00:25:09 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-07-18 00:25:09 +0200
commitefe46f68a9d0363fd58222048ddfa9efaf1bc9cd (patch)
tree10eaca8f6ea888d0e076cd356126f61d3cce2f54 /website
parent97974b9104430d4c31ef003da3643a7905af46c6 (diff)
downloadlombok-efe46f68a9d0363fd58222048ddfa9efaf1bc9cd.tar.gz
lombok-efe46f68a9d0363fd58222048ddfa9efaf1bc9cd.tar.bz2
lombok-efe46f68a9d0363fd58222048ddfa9efaf1bc9cd.zip
Added Cleanup features text.
Diffstat (limited to 'website')
-rw-r--r--website/features/Cleanup.html62
1 files changed, 62 insertions, 0 deletions
diff --git a/website/features/Cleanup.html b/website/features/Cleanup.html
new file mode 100644
index 00000000..53c94701
--- /dev/null
+++ b/website/features/Cleanup.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <link rel="stylesheet" type="text/css" href="../logi/reset.css" />
+ <link rel="stylesheet" type="text/css" href="features.css" />
+ <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
+ <meta name="description" content="Spice up your java" />
+ <title>@Cleanup</title>
+ <!--[if lt IE 7]><script type="text/javascript" src="logi/iepngfix_tilebg.js"></script><![endif]-->
+</head><body><div id="pepper">
+ <div class="meat">
+ <div class="minimumHeight"></div>
+ <div class="header"><a href="../index.html">Project Lombok</a></div>
+ <h1>@Cleanup</h1>
+ <div class="overview">
+ <h3>Overview</h3>
+ <p>
+ You can use <code>@Cleanup</code> to ensure a given resource is automatically cleaned up before the code execution path exits your
+ current scope. You do this by annotating any local variable declaration with the <code>@Cleanup</code> annotation like so:<br />
+ <code>@Cleanup InputStream in = new FileInputStream("some/file");</code></br />
+ As a result, at the end of the scope you're in, <code>in.close()</code> is called. This call is guaranteed to run by way of a
+ try/finally construct. Look at the example below to see how this works.
+ </p><p>
+ If the type of object you'd like to cleanup does not have a <code>close()</code> method, but some other no-argument method, you can
+ specify the name of this method like so:<br />
+ <code>@Cleanup("dispose") org.eclipse.swt.widgets.CoolBar bar = new CoolBar(parent, 0);</code><br />
+ By default, the cleanup method is presumed to be <code>close()</code>. A cleanup method that takes argument cannot be called via
+ <code>@Cleanup</code>.
+ </p>
+ </div>
+ <div class="snippets">
+ <div class="pre">
+ <h3>With Lombok</h3>
+ <div class="snippet">@HTML_PRE@</div>
+ </div>
+ <div class="sep"></div>
+ <div class="post">
+ <h3>Vanilla Java</h3>
+ <div class="snippet">@HTML_POST@</div>
+ </div>
+ </div>
+ <div style="clear: left;"></div>
+ <div class="overview">
+ <h3>Small print</h3><div class="smallprint">
+ <p>
+ If your code throws an exception, and the cleanup method call that is then triggered also throws an exception, then the original exception
+ is hidden by the exception thrown by the cleanup call. You should <em>not</em> rely on this 'feature'. Preferably, lombok would like to generate
+ code so that, if the main body has thrown an exception, any exception thrown by the close call is silently swallowed (but if the main body
+ exited in any other way, exceptions by the close call will not be swallowed). The authors of lombok do not currently know of a feasible way
+ to implement this scheme, but if java updates allow it, or we find a way, we'll fix it.
+ </p><p>
+ You do still need to handle any exception that the cleanup method can generate!
+ </p>
+ </div>
+ </div>
+ <footer>
+ <a href="index.html">Back to features</a> | <a href="Data.html">Previous feature (@Data)</a> | <a href="Synchronized.html">Next feature (@Synchronized)</a><br />
+ <span class="copyright">Copyright &copy; 2009 Reinier Zwitserloot and Roel Spilker, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT licence</a>.</span>
+ </footer>
+ <div style="clear: both;"></div>
+ </div>
+</div></body></html>