Skip to content

Instantly share code, notes, and snippets.

@Randgalt
Forked from poetix/Nonchalantly.java
Created December 21, 2017 17:11
Show Gist options
  • Save Randgalt/a50d4ae7bb48e4b9d8c2d502ec00c5a9 to your computer and use it in GitHub Desktop.
Save Randgalt/a50d4ae7bb48e4b9d8c2d502ec00c5a9 to your computer and use it in GitHub Desktop.
A Java 8 class for when you just don't give a fuck about that checked exception
public interface Nonchalantly<T> {
static <T, E extends Throwable> T invoke(Nonchalantly<T> f) throws E {
try {
return f.run();
} catch (Throwable e) {
throw (E) e;
}
}
T run() throws Throwable;
// USAGE
// BeanInfo beanInfo = Nonchalantly.invoke(() -> Introspector.getBeanInfo(iface));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment