·以Function<V, R>接口为例子。
·Function<V, R>接口:V入参,R出参。
即:V为传入接口Function中重写方法参数类型,R为重写方法的返回值类型。
public class RRR {
public static void main(String[] args) {
RRR r = new RRR();
//lamda
Long i = r.fun( s -> { //s=999L
//重写了apply(Long s)方法,
//重写内容:
/*
* Long apply(Long s){
* System.out.println(s+"===---==="+s);
* }
*
**/
System.out.println(s+"===---==="+s); // 999===---===999
return 10000;//返回到vFunc.apply(999L)方法,注意返回类型是Integer而不是Long
},100L);
System.out.println(i);//10000+100L=10100
}
//接口参数的方法
public Long fun(Function<Long, Integer> vFunc,Long gg) {
//vFunc.apply(999L) 999L 传给 s
Integer apply = vFunc.apply(999L);
return apply+ gg;//10000+999L
}
}
结果:
999===---===999
10100