当前位置:网站首页>Lambda expression: an article takes you through
Lambda expression: an article takes you through
2022-07-02 22:59:00 【Xiaopucai learns Java】
One ,JDK8 introduce Lambda expression
JDk1.8 in the future Interface can There are common ways , It's not just abstract methods , The method is default Embellished , And this method , His implementation subclasses can call this method .
Define common methods in the interface , It is generally used to modify the shortcomings of the previous version . Developers can hardly use .
dafault Keyword represents a common method in an interface , Don't omit .

Two , Functional interface : An interface has and has only one abstract method , It's a functional interface .
Use @FunctionalInterface To check whether it is a functional interface , There can only be one , No more , Not without it

1, Through anonymous inner classes , To implement functional interfaces


2,Lambda expression , To implement the interface


3、 ... and ,lambda expression
Lambda Expressions are based on functions and interfaces , If there are multiple interfaces or no interfaces , You won't find the abstract methods in the interface one by one .Lambda The expression will become error prone .
It is the implementation that only retains the parameters and body of the method .
Lambda Four forms of expressions :
1, No return value , No parameter

2, No return value, parameter

3, With return value and no parameter

4, No return value no parameter
Four ,Lambda Features of expressions :
1, If the implementation of a method has only one line of code , It can be omitted {}

2, If method has only one parameter , Then brackets can be omitted
3, You can omit the types of expression parameters ( Or omit it all , Or don't omit it all )

4, If the method body has a return value and the method body has only one line , It can be omitted {},return

边栏推荐
猜你喜欢

AES高級加密協議的動機闡述
![加油站[问题分析->问题转换->贪心]](/img/15/5313f900abedb46ce82d8ab81af1d7.png)
加油站[问题分析->问题转换->贪心]

Lambda表达式:一篇文章带你通透

World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
![[chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?](/img/b5/e746dd115995e82c93f667c58a601c.png)
[chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?

QT qsplitter splitter
![Gas station [problem analysis - > problem conversion - > greed]](/img/15/5313f900abedb46ce82d8ab81af1d7.png)
Gas station [problem analysis - > problem conversion - > greed]
![Jielizhi, production line assembly link [chapter]](/img/0d/102596ad13aafd9c6133509d9064dd.png)
Jielizhi, production line assembly link [chapter]
![[羊城杯2020]easyphp](/img/12/da28f738e50e625b0a66a94af3703d.png)
[羊城杯2020]easyphp

數據分析學習記錄--用EXCEL完成簡單的單因素方差分析
随机推荐
Webrtc audio and video capture and playback examples and mediastream media stream analysis
Golang面试整理 三 简历如何书写
牛客网:龙与地下城游戏
杰理之直接触摸样机的顶针反应不正常【篇】
AES高級加密協議的動機闡述
移动端 1px 像素兼容性问题,实现1px 边框
Introduction and response to high concurrency
世界环境日 | 周大福用心服务推动减碳环保
How does Jerry test the wrong touch rate of keys [chapter]
景联文科技低价策略帮助AI企业降低模型训练成本
海思3559万能平台搭建:在截获的YUV图像上旋转操作
Golang interview finishing three resumes how to write
分布式监控系统zabbix
Niuke: Dragon and dungeon games
杰理之充电拔出,无法触摸开机【篇】
Golang's learning route
[leetcode] there are duplicate elements [217]
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
Hanging mirror security won four global infosec awards on rsac2022
解决Chrome浏览器和Edeg浏览器主页被篡改的方法