import java.util.Collections; import java.util.Set; class Test { Database database; Set getItems() { return database.perform(connection -> { try (AutoCloseable c = null) { try (AutoCloseable d = null) { return Collections.emptySet(); } } }); } public interface Database { V perform(BusinessLogic logic); } public interface BusinessLogic { V execute(String connection) throws Exception; } }