/** * This method allows a Consumer which throws exceptions to be used in places which expects a Consumer. * * @param consumer instances of the {@code ConsumerWithExceptions} functional interface * @param <T> the type of the input to the function * @param <E> the type of Exception * @return an instance of the {@code Consumer} */ public static <T, E extends Exception> Consumer<T> rethrowConsumer(ConsumerWithExceptions<T, E> consumer) { return t -> { try { consumer.accept(t); } catch (Exception exception) { throwAsUnchecked(exception); } }; }
/** * This method allows a Consumer which throws exceptions to be used in places which expects a Consumer. * * @param consumer instances of the {@code ConsumerWithExceptions} functional interface * @param <T> the type of the input to the function * @param <E> the type of Exception * @return an instance of the {@code Consumer} */ public static <T, E extends Exception> Consumer<T> rethrowConsumer(ConsumerWithExceptions<T, E> consumer) { return t -> { try { consumer.accept(t); } catch (Exception exception) { throwAsUnchecked(exception); } }; }