@Target(value=LOCAL_VARIABLE)
@Retention(value=SOURCE)
public @interface Cleanup
Complete documentation is found at the project lombok features page for @Cleanup.
Example:
public void copyFile(String in, String out) throws IOException {
@Cleanup FileInputStream inStream = new FileInputStream(in);
@Cleanup FileOutputStream outStream = new FileOutputStream(out);
byte[] b = new byte[65536];
while (true) {
int r = inStream.read(b);
if (r == -1) break;
outStream.write(b, 0, r);
}
}
Will generate:
public void copyFile(String in, String out) throws IOException {
@Cleanup FileInputStream inStream = new FileInputStream(in);
try {
@Cleanup FileOutputStream outStream = new FileOutputStream(out);
try {
byte[] b = new byte[65536];
while (true) {
int r = inStream.read(b);
if (r == -1) break;
outStream.write(b, 0, r);
}
} finally {
if (out != null) out.close();
}
} finally {
if (in != null) in.close();
}
}
| Modifier and Type | Optional Element and Description |
|---|---|
java.lang.String |
value |
Copyright © 2009-2015 The Project Lombok Authors, licensed under the MIT licence.