Skip to content

Instantly share code, notes, and snippets.

@saswata-dutta
Created July 13, 2023 06:52
Show Gist options
  • Save saswata-dutta/e9a82c0ddb10f7ee9fc974f6690ad18f to your computer and use it in GitHub Desktop.
Save saswata-dutta/e9a82c0ddb10f7ee9fc974f6690ad18f to your computer and use it in GitHub Desktop.
@FunctionalInterface
interface ThrowingConsumer<T, E extends Exception> {
void accept(T t) throws E;
static <T> Consumer<T> unchecked(ThrowingConsumer<T, Exception> t) {
return arg -> {
try {
t.accept(arg);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
};
}
}
// threads.forEach(ThrowingConsumer.unchecked(Thread::join));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment