Details
Description
The following type of resource usages:
AutoCloseable resource = ...; try { // do something with resource } finally { resource.close(); }
AutoCloseable resource = null; try { resource = ...; // do something with resource } finally { if (resource != null) { resource.close(); } }
and similar constructs can be trivially replaced with Java 7's try-with-resource statement:
try (AutoCloseable resource = ...) { // do something with resource }
This brings more concise code with less chance of causing resource leaks.