Package dev.enola.common.function
Class Sneaker
java.lang.Object
dev.enola.common.function.Sneaker
👟 Sneaker for (controlled) "sneaky Throw".
See e.g.
https://4comprehension.com/sneakily-throwing-exceptions-in-lambda-expressions-in-java/ and
https://www.baeldung.com/java-lambda-exceptions, but also
https://github.com/google/guava/wiki/Why-we-deprecated-Throwables.propagate, for some related
background. Contrary to what those and similar posts state, the way this is done here is actually
entirely "safe" in Java... note that the trick here, and important difference to a general 👟
Sneaker, is that the MoreStreams.forEach(Stream, CheckedConsumer) signature actually
declares the throws E - so it's safe!
-
Method Summary
Modifier and TypeMethodDescriptionsneakyConsumer(CheckedConsumer<T, E> checkedConsumer) sneakyFunction(CheckedFunction<T, R, E> checkedFunction)
-
Method Details
-
sneakyConsumer
public static <T,E extends Exception> Consumer<T> sneakyConsumer(CheckedConsumer<T, E> checkedConsumer) -
sneakyFunction
public static <T,R, Function<T,E extends Exception> R> sneakyFunction(CheckedFunction<T, R, E> checkedFunction)
-