Skip to content

Instantly share code, notes, and snippets.

@pellse
Created November 6, 2017 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pellse/4f8d176b88568de5d0cb31c06e84332a to your computer and use it in GitHub Desktop.
Save pellse/4f8d176b88568de5d0cb31c06e84332a to your computer and use it in GitHub Desktop.
@SuppressWarnings("unchecked")
public static <T, E extends Exception> T sneakyThrow(Exception e) throws E {
throw (E) e;
}
public static <T, R> Function<T, R> unchecked(CheckedFunction<T, R> checkedFunction) {
return t -> {
try {
return checkedFunction.apply(t);
} catch (Exception e) {
return sneakyThrow(e);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment