@Target(LOCAL_VARIABLE)
@Retention(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 (outStream != null) outStream.close();
}
} finally {
if (inStream != null) inStream.close();
}
}
| Modifier and Type | Optional Element | Description |
|---|---|---|
java.lang.String |
value |
Copyright © 2009-2018 The Project Lombok Authors, licensed under the MIT licence.