Consumer
Stay organized with collections
Save and categorize content based on your preferences.
|
Known Indirect Subclasses
|
Represents an operation that accepts a single input argument and returns no
result. Unlike most other functional interfaces, Consumer is expected
to operate via side-effects.
This is a functional interface
whose functional method is accept(Object).
Public Method Summary
|
abstract
void
|
accept(T t)
Performs this operation on the given argument.
|
|
Consumer<T>
|
andThen( Consumer<? super T> after)
Returns a composed Consumer that performs, in sequence, this
operation followed by the after operation.
|
Public Methods
public
abstract
void
accept
(T t)
Performs this operation on the given argument.
public
Consumer<T>
andThen
(Consumer<? super T> after)
Returns a composed Consumer that performs, in sequence, this
operation followed by the after operation. 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.
Parameters
| after |
the operation to perform after this operation |
Returns
- a composed
Consumer that performs in sequence this
operation followed by the after operation
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["`Consumer` is a functional interface representing an operation that takes an input and produces no result, primarily working through side-effects."],["It includes the `accept` method to perform the operation on the given input and the `andThen` method to chain multiple `Consumer` instances for sequential execution."],["`Consumer` is commonly used in scenarios where actions need to be performed on data without necessarily returning a value, such as logging or modifying data structures."]]],["The `Consumer` interface represents an operation with a single input argument and no return value, typically using side-effects. It features the `accept(T t)` method, which executes the operation on the provided argument. Another key method is `andThen(Consumer\u003c? super T\u003e after)`, which allows sequencing operations by executing the `after` operation subsequent to the primary operation. `andThen` will relay exceptions to the caller or if the first operation fails it will not perform the `after` operation.\n"]]