Interface Consumer5<A,B,C,D,E>

Type Parameters:
A - The type of the first argument to the operation.
B - The type of the second argument to the operation.
C - The type of the third argument to the operation.
D - The type of the fourth argument to the operation.
E - The type of the fifth argument to the operation.
All Known Subinterfaces:
ThrowingConsumer5<A,B,C,D,E>
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 Consumer5<A,B,C,D,E>
A functional interface representing an operation that accepts five arguments and returns no result.

This interface extends the standard Java Consumer pattern to support five-argument consumers. It's useful when you need to pass operations with five parameters to methods that expect functional interfaces, such as in iteration, builders, or callback patterns.

Features:
  • Functional interface - can be used with lambda expressions and method references
  • Composition support - provides andThen(Consumer5) for operation chaining
  • Side-effect operations - designed for operations that perform side effects rather than return values
Use Cases:
  • Five-argument operations in iteration patterns
  • Builder methods that accept five-parameter operations
  • Callback patterns with five parameters
  • Event handlers that process five values
Usage:

// Lambda expression Consumer5<String,Integer,Boolean,Double,Long> printer = (name, age, active, score, timestamp) -> System.out.println(name + ": age=" + age + ", active=" + active + ", score=" + score + ", time=" + timestamp); printer.apply("Alice", 30, true, 95.5, 1234567890L); // Operation composition Consumer5<String,Integer,Boolean,Double,Long> validate = (s, i, b, d, l) -> { if (i < 0 || d < 0 || l < 0) throw new IllegalArgumentException(); }; Consumer5<String,Integer,Boolean,Double,Long> process = (s, i, b, d, l) -> process(s, i, b, d, l); Consumer5<String,Integer,Boolean,Double,Long> validateAndProcess = validate.andThen(process); validateAndProcess.apply("data", 42, true, 10.5, 9876543210L); // Validates then processes

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default Consumer5<A,B,C,D,E>
    andThen(Consumer5<? super A,? super B,? super C,? super D,? super E> after)
    Returns a composed Consumer5 that performs, in sequence, this operation followed by the after operation.
    void
    apply(A a, B b, C c, D d, E e)
    Performs this operation on the given arguments.
  • Method Details

    • andThen

      default Consumer5<A,B,C,D,E> andThen(Consumer5<? super A,? super B,? super C,? super D,? super E> after)
      Returns a composed Consumer5 that performs, in sequence, this operation followed by the after operation.

      This method enables operation composition, allowing you to chain multiple operations together. If performing either operation throws an exception, it is relayed to the caller of the composed operation. If performing this operation throws an exception, the after operation will not be performed.

      Example:

      Consumer5<String,Integer,Boolean,Double,Long> log = (s, i, b, d, l) -> logger.info(s + ": " + i + ", " + b + ", " + d + ", " + l); Consumer5<String,Integer,Boolean,Double,Long> store = (s, i, b, d, l) -> cache.put(s, i, b, d, l); Consumer5<String,Integer,Boolean,Double,Long> logAndStore = log.andThen(store); logAndStore.apply("data", 100, true, 50.0, 1234567890L); // Logs and stores

      Parameters:
      after - The operation to perform after this operation. Must not be null.
      Returns:
      A composed Consumer5 that performs in sequence this operation followed by the after operation.
      Throws:
      NullPointerException - if after is null.
    • apply

      void apply(A a, B b, C c, D d, E e)
      Performs this operation on the given arguments.
      Example:

      Consumer5<String,Integer,Boolean,Double,Long> handler = (key, value, flag, weight, time) -> { map.put(key, value); if (flag) cache.invalidate(key); stats.record(weight, time); }; handler.apply("user", 12345, true, 1.5, 9876543210L);

      Parameters:
      a - The first operation argument.
      b - The second operation argument.
      c - The third operation argument.
      d - The fourth operation argument.
      e - The fifth operation argument.