当前位置:网站首页>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

边栏推荐
- Mask R-CNN
- [LeetCode] 数组中的第K个最大元素【215】
- LeetCode 968. 监控二叉树
- 用sentinel熔断比例阈值改不了,设置慢调用比例没效果
- 首批 | 腾讯云完成国内首个云原生安全成熟度评估
- `Usage of ${}`
- Rails 3 activerecord: sort by association count - rails 3 activerecord: order by count on Association
- 分布式监控系统zabbix
- JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
- 世界环境日 | 周大福用心服务推动减碳环保
猜你喜欢
随机推荐
[chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?
Jerry's prototype has no touch, and the reinstallation becomes normal after dismantling [chapter]
大一学习分享
Chow-Liu Tree
Stop slave is stuck -- the event of the transaction is not copied completely
成功改变splunk 默认URL root path
杰理之充电拔出,无法触摸开机【篇】
PMP project integration management
Using rendertext() to output multiple lines of text with rendertext() in R shiny
[chestnut sugar GIS] ArcMap - how to batch modify the font, color, size, etc. of annotation elements
[Solved] Splunk: Cannot get username when all users are selected“
送给即将工作的自己
Performance optimization - rigorous mode
Golang面试整理 三 简历如何书写
[leetcode] reverse string [344]
Storage unit conversion
What is the'function'keyword used in some bash scripts- What is the 'function' keyword used in some bash scripts?
[Luogu p1541] tortoise chess [DP]
[leetcode] reverse the word III in the string [557]
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection








