当前位置:网站首页>函数式接口&Lambda表达式——简单应用笔记
函数式接口&Lambda表达式——简单应用笔记
2022-07-30 08:21:00 【Rose*留白ق೨】
以下是根据资料和实验得出的理解:
1、Lambda表达式的使用与函数式接口有关
2、函数式接口有且仅有一个抽象方法
函数式接口、Lambda表达式不懂的可以去参考其他文章
以下代码可以自行复制粘贴看看执行效果
//函数式接口 接口内仅有一个方法
@FunctionalInterface
public interface MyFunctionalInterface {
int test(int a,int b);
}
import java.util.ArrayList;
import java.util.List;
public class testLambda {
private static int sum(MyFunctionalInterface myFunctionalInterface,int a,int b){
return myFunctionalInterface.test(a,b);
}
public static void main(String[] args) {
//Lambda表达式经典例子
List<String> list = new ArrayList<>();
list.add("abc");
list.add("def");
list.add("ghi");
list.forEach(item -> System.out.println(item));
//函数式接口的基本使用 基本语法: (parameters) -> expression 或 (parameters) ->{ statements; }
MyFunctionalInterface myFunctionalInterface = (int a,int b)-> {
return a+b;
};
//简写
MyFunctionalInterface myFunctionalInterface1 = (int a,int b)-> a+b;
int result = myFunctionalInterface1.test(3,2);
System.out.println(result);
//函数式接口的典型使用场景是作为方法的参数
int result1 = sum((int a,int b) -> a+b,20,36);
System.out.println(result1);
}
}
边栏推荐
- 网络/信息安全顶刊及相关期刊会议
- [Unity]UI切换环形滚动效果
- 积分专题笔记-积分的定义
- How to implement Golang DES encryption and decryption?
- ACL 2022 | Introduce angular margin to construct comparative learning objectives and enhance text semantic discrimination ability
- 经典毕业设计:基于SSM实现高校后勤报修系统
- Is R&D moving to FAE (Field Application Engineer), is it moving away from technology?Is there a future?
- 【蓝桥杯选拔赛真题45】Scratch猫鼠游戏 少儿编程scratch蓝桥杯选拔赛真题讲解
- Integral Special Notes - Definition of Integral
- 剖析SGI STL空间配置器(空间配置器的重要性和重要成员及函数)
猜你喜欢
随机推荐
HCIP --- MPLS VPN实验
嘉为鲸翼·多云管理平台荣获信通院可信云技术服务最佳实践
Kotlin 值类 - value class
How to use Jmeter to carry out high concurrency in scenarios such as panic buying and seckill?
How to implement Golang DES encryption and decryption?
20个电路能懂5个以上,足以证明你在电子行业混过!
stugc_paper
【HMS core】【FAQ】HMS Toolkit典型问题合集1
用示波器揭示以太网传输机制
SQL window function
【网络攻防】常见的网络攻防技术——黑客攻防(通俗易懂版)
电路分析:运放和三极管组成的恒流源电路
集合相关Collection
Integral Special Notes - Definition of Integral
【三子棋】——玩家VS电脑(C语言实现)
ACL 2022 | Introduce angular margin to construct comparative learning objectives and enhance text semantic discrimination ability
ant-design form form verification upload component (with personal packaged upload component)
SRAM与DRAM的区别
sort函数使用cmp出错Line 22: Char 38: error: reference to non-static member function must be called
Splunk tag 的利用场景




![[Mini Program Column] Summarize the development specifications of uniapp to develop small programs](/img/7b/110d324eba00652e4987bc623a5bc6.png)




