Interface Consumer<T>

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

    @ConsumerType
    @FunctionalInterface
    public interface Consumer<T>
    A function that accepts a single argument and produces no result.

    This is a functional interface and can be used as the assignment target for a lambda expression or method reference.

    Since:
    1.1
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      void accept​(T t)
      Applies this function to the specified argument.
      default Consumer<T> andThen​(Consumer<? super T> after)
      Compose the specified Consumer to be called after this Consumer.
      static <T> Consumer<T> asConsumer​(java.util.function.Consumer<T> wrapped)
      Returns a Consumer which wraps a java.util.function.Consumer.
      static <T> java.util.function.Consumer<T> asJavaConsumer​(Consumer<T> wrapped)
      Returns a java.util.function.Consumer which wraps the specified Consumer and throws any thrown exceptions.
      static <T> java.util.function.Consumer<T> asJavaConsumerIgnoreException​(Consumer<T> wrapped)
      Returns a java.util.function.Consumer which wraps the specified Consumer and discards any thrown Exceptions.
    • Method Detail

      • accept

        void accept​(T t)
             throws java.lang.Exception
        Applies this function to the specified argument.
        Parameters:
        t - The input to this function.
        Throws:
        java.lang.Exception - An exception thrown by the method.
      • andThen

        default Consumer<T> andThen​(Consumer<? super T> after)
        Compose the specified Consumer to be called after this Consumer.
        Parameters:
        after - The Consumer to be called after this Consumer is called. Must not be null.
        Returns:
        A Consumer composed of this Consumer and the specified Consumer.
      • asJavaConsumer

        static <T> java.util.function.Consumer<T> asJavaConsumer​(Consumer<T> wrapped)
        Returns a java.util.function.Consumer which wraps the specified Consumer and throws any thrown exceptions.

        The returned java.util.function.Consumer will throw any exception thrown by the wrapped Consumer.

        Type Parameters:
        T - The type of the function input.
        Parameters:
        wrapped - The Consumer to wrap. Must not be null.
        Returns:
        A java.util.function.Consumer which wraps the specified Consumer.
      • asJavaConsumerIgnoreException

        static <T> java.util.function.Consumer<T> asJavaConsumerIgnoreException​(Consumer<T> wrapped)
        Returns a java.util.function.Consumer which wraps the specified Consumer and discards any thrown Exceptions.

        The returned java.util.function.Consumer will discard any Exception thrown by the wrapped Consumer.

        Type Parameters:
        T - The type of the function input.
        Parameters:
        wrapped - The Consumer to wrap. Must not be null.
        Returns:
        A java.util.function.Consumer which wraps the specified Consumer.
      • asConsumer

        static <T> Consumer<T> asConsumer​(java.util.function.Consumer<T> wrapped)
        Returns a Consumer which wraps a java.util.function.Consumer.
        Type Parameters:
        T - The type of the function input.
        Parameters:
        wrapped - The java.util.function.Consumer to wrap. Must not be null.
        Returns:
        A Consumer which wraps the specified java.util.function.Consumer.