0 votes
in JAVA by
What are Supplier and Consumer Functional interface?

1 Answer

0 votes
by

The Supplier is a functional interface that returns an object. It's similar to the factory method or new(), which returns an object.

The Supplier has get() functional method, which doesn't take any argument and return an object of type T. This means you can use it anytime you need an object.

Since it is a functional interface, you can also use it as the assignment target for a lambda expression or method reference.

A Consumer is also a functional interface in JDK 8, which represents an operation that accepts a single input argument and returns no result.

Unlike other functional interfaces, Consumer is expected to operate via side-effects. The functional method of Consumer is accept(T t), and because it's a functional interface, you can use it as the assignment target for a lambda expression or method interface in Java 8.

Related questions

0 votes
asked Oct 11, 2020 in JAVA by SakshiSharma
0 votes
asked Apr 13, 2023 in JAVA by Robin
...