Function Interface::
Represents a function that accepts one argument and produces a result.
This is a functional interface whose functional method is
apply(Object)
.BiFunction<T,U,R>
Represents a function that accepts two arguments and produces a result. This is the two-arity specialization of
Please refer below link for more inforamation:
https://docs.oracle.com/javase/8/docs/api/java/util/function/package-summary.html
package utlfunc;
import java.util.function.BiFunction;
import java.util.function.DoubleFunction;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.LongFunction;
public class GraspFucnIntrface {
public static void main(String[] args) {
Function<Integer, Integer> fnction=(x)->checkInt(x);
System.out.println("Function:: checkInt() " + fnction.apply(6));
Function<Integer, Integer> fnctionExp=(x)-> {return x;};
fnctionExp.andThen(fnction).apply(8);
BiFunction<String, Integer,Boolean> biFucntion=(x,y)->checkStiringEmpty(x, y);
System.out.println("from BIFUNCTION() ::checkStiringEmpty():" + biFucntion.apply("functioninterface", 12));
IntFunction<Integer> fnctionInt=(x)->checkInt(x);
System.out.println("Function:: checkInt() " + fnctionInt.apply(6));
LongFunction<Long> fnctionLng=(x)->checkLng(x);
System.out.println("Function:: checkLng() " + fnctionLng.apply(6l));
DoubleFunction<Double> fnctionDbl=(x)->checkDbl(x);
System.out.println("Function:: checkLng() " + fnctionDbl.apply(6.0));
}
public static boolean checkStiringEmpty(String check,int b) {
return check.length()>0 && b>0?true:false;
}
public static int checkInt(int b) {
return b;
}
public static Long checkLng(long b) {
return b;
}
public static Double checkDbl(Double b) {
return b;
}
}
Function
.
This is a functional interface whose functional method is
apply(Object, Object)
.https://docs.oracle.com/javase/8/docs/api/java/util/function/package-summary.html
import java.util.function.BiFunction;
import java.util.function.DoubleFunction;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.LongFunction;
public class GraspFucnIntrface {
public static void main(String[] args) {
Function<Integer, Integer> fnction=(x)->checkInt(x);
System.out.println("Function:: checkInt() " + fnction.apply(6));
Function<Integer, Integer> fnctionExp=(x)-> {return x;};
fnctionExp.andThen(fnction).apply(8);
BiFunction<String, Integer,Boolean> biFucntion=(x,y)->checkStiringEmpty(x, y);
System.out.println("from BIFUNCTION() ::checkStiringEmpty():" + biFucntion.apply("functioninterface", 12));
IntFunction<Integer> fnctionInt=(x)->checkInt(x);
System.out.println("Function:: checkInt() " + fnctionInt.apply(6));
LongFunction<Long> fnctionLng=(x)->checkLng(x);
System.out.println("Function:: checkLng() " + fnctionLng.apply(6l));
DoubleFunction<Double> fnctionDbl=(x)->checkDbl(x);
System.out.println("Function:: checkLng() " + fnctionDbl.apply(6.0));
}
public static boolean checkStiringEmpty(String check,int b) {
return check.length()>0 && b>0?true:false;
}
public static int checkInt(int b) {
return b;
}
public static Long checkLng(long b) {
return b;
}
public static Double checkDbl(Double b) {
return b;
}
}
Output ::
No comments:
Post a Comment