Introduction
In this tutorial we will look at the use of Consumer a functional interface introduced in java 8.
Refer The video Tutorial for detail
Use Case
Consumer is a functional interface which is used to modify value based on some data.The sample code is shown below.
//return type is void
Consumer<Integer> consumer=new Consumer<Integer>() {
@Override
public void accept(Integer i) {
System.out.println("Nothing is returned in case of consumer");
}
}
|
The above case will not return anything it will just consume some data to process it.
Conclusion
In this tutorial we saw the use case of functional interface - Consumer. which is introduced in java 8 to modify data by consuming it in response.
No comments:
Post a Comment