Java 8 functional Interfaces.
What is Functional programming:
Functional programming is a mathematical style of programming which executes sequentially, it takes inputs and gives output, it is not preferable to modify the input data. It's totally about programming with values.Sample:
function addNumbers(a, b){
return a+b;
}
![]() |
| Functional Programming. |
Java 8 functional programming:
An interface with a single method is known as a Functional Interface.
what is lambda expression:
Lambda expression is a separator between input and output.
An interface with a single method is known as a Functional Interface.
- Whether the interface have only one abstract (unimplemented) method?
- Whether the parameters of the lambda expression match the parameters of the single method?
- Whether the return type of the lambda expression match the return type of the single method?
If the answer is true for above three questions, then the given lambda expression is matched successfully against the interface.
Types of Functional interfaces:
These features are functional interfaces (an interface with only one abstract method) which belongs to the java.util.function package.
1. Consumers
public interface Consumer<T>
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).2. Suppliers
public interface Supplier<T>
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
3. Predicates
public interface Predicate<T>
Represents a predicate (boolean-valued function) of one argument.This is a functional interface whose functional method is
test(Object).

Comments
Post a Comment