Interface Consumer<T,E extends Exception>

Type Parameters:
T - the type of the input to the function
E - the type of the exception that may be thrown
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Consumer<T,E extends Exception>
Represents a function that accepts one argument, produces no result and (optionally) throws an Exception.

This is a functional interface whose functional method is accept(Object) )}.

Since:
1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    accept(T arg)
    Applies this function to the given argument.
    default Consumer<T>
    Wraps this function that may throw an exception into a function that will throw a RuntimeException if the original function throws an exception.
    static <T> Consumer<T>
    unchecked(Consumer<? super T,?> function)
    Wraps a function that may throw an exception into a function that will throw a RuntimeException if the original function throws an exception.
  • Method Details

    • accept

      void accept(T arg) throws E
      Applies this function to the given argument.
      Parameters:
      arg - the function argument
      Throws:
      E - if an exception occurs
      Since:
      1.0
    • unchecked

      static <T> Consumer<T> unchecked(Consumer<? super T,?> function)
      Wraps a function that may throw an exception into a function that will throw a RuntimeException if the original function throws an exception.
      Type Parameters:
      T - the type of the input to the function
      Parameters:
      function - the function to wrap
      Returns:
      a function that will throw a RuntimeException if the original function throws an exception
      Since:
      1.0
    • unchecked

      default Consumer<T> unchecked()
      Wraps this function that may throw an exception into a function that will throw a RuntimeException if the original function throws an exception.
      Returns:
      a function that will throw a RuntimeException if the original function throws an exception
      Since:
      1.0
      See Also: