BiFunction函数式接口,只有一个apply()的抽象函数,这个函数接收两个入参,BiFunction函数式接口中的apply()方法表示对两个输入的结果执行某种操作以后返回操作后的结果,这个操作在运行的时候运行的时候动态确定。

public class Main {public static void main(String[] args) throws Exception {/*** 类似变量声明式定义函数式接口* 左边是该函数式接口的具体实例,右边是具体行为*///BiFunction<Integer,Integer,Integer> bf = (a,b)->a+b;System.out.println(operator(10,21,(a,b)->a+b));System.out.println(operator(10,2,(a,b)->a-b));System.out.println(operator(8,4,(a,b)->a*b));System.out.println(operator(10,2,(a,b)->a/b));}public static Integer operator(Integer a, Integer b, BiFunction<Integer,Integer,Integer> bf){return bf.apply(a,b);}}
vip算法班往期教学视频链接地址
https://meeting.tencent.com/v2/cloud-record/share?id=f95d29c9-ca8d-478f-af49-f76b220e2c9b&from=3
访问密码:btn
vip永久刷题群双十二优惠价~
奔跑的小梁,公众号:梁霖编程工具库leetcode刷题直播教学,手把手带你刷题,双十二价格优惠通知
文章转载自梁霖编程工具库,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




