Consumer (I)
Consumer is a functional interface which contains only one method i.e. accept().
It accept some input and perform required operations and not required to return any value.
{
public void accept(T t);
}
Consumer (I)
Consumer is a functional interface which contains only one method i.e. accept().
It accept some input and perform required operations and not required to return any value.
{
public void accept(T t);
}
Function Chaining
Two functions can be combined to from a more complex function
first f1 then f2
i.e. f1.andThen(f2).apply(i);
first f2 then f1
f1.compose(f2).apply(i);
Functional Interface method can be mapped to our specified method by using :: (double colon) operator. This is called method reference.
Our
specified method can be either static method or instance
method.
Functional Interface method and our specified method should have same argument
types, except this the remaining things like return type, method name,
modifiers etc. are not required to match.
Syntax:
Case1:
If our specified method is static method
classname::methodName
Case2:
If the method name is instance method
objRef::methodName
Functional Interface can refer lambda expression and
Functional Interface can also refer method reference.
Hence lambda expression can be replace with method reference.
Hence method reference is alternative syntax to lambda expression.
import java.util.Scanner;
// function to validate the entry made by user in user form function validateEntry (){ // declare a variable and referernece of active goog...