@FunctionalInterface @Generated(value="uk.kludje.annotation.processor.UncheckedFunctionalInterfaceProcessor") public interface UCloseableResource extends CloseableResource
void $close() throws Throwable USING A LAMBDA; INVOKE void close().
A functional interface for handling checked exceptions. See parent type for interface intent.
void close() invokes void $close()
and throws anything thrown by void $close().
General example using java.lang.Runnable that reduces 11 lines to a single line.
Call someMethodThatThrowsException in throwsNothing:
public void someMethodThatThrowsException() throws IOException {
// I/O functionality
}
public void throwsNothing(Runnable r) {
r.run();
}
Before:
public void yourMethod() throws IOException {
try {
throwsNothing(() -> {
try {
someMethodThatThrowsException();
} catch (IOException e) {
throw new SomeWrapperException(e);
}
});
} catch(SomeWrapperException w) {
throw (IOException) w.getCause();
}
}
After:
public void yourMethod() throws IOException {
throwsNothing((URunnable) this::someMethodThatThrowsException);
}
Method public static UCloseableResource asUCloseableResource(UCloseableResource t)
provides a convenience method for manufacturing types as an alternative to casting.
| Modifier and Type | Method and Description |
|---|---|
void |
$close() |
static UCloseableResource |
asUCloseableResource(UCloseableResource t) |
default void |
close()
Overrides the parent method which throws
Exception. |
expecteddefault void close()
CloseableResourceException.
Combined with CloseableResource.expected() this type can declare checked it throws any type.close in interface java.lang.AutoCloseableclose in interface CloseableResourcevoid $close()
throws java.lang.Throwable
java.lang.Throwablestatic UCloseableResource asUCloseableResource(UCloseableResource t)