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

边栏推荐
猜你喜欢

悬镜安全在RSAC2022上斩获Global InfoSec Awards四项大奖

泛型与反射,看这篇就够了

World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
![加油站[问题分析->问题转换->贪心]](/img/15/5313f900abedb46ce82d8ab81af1d7.png)
加油站[问题分析->问题转换->贪心]
![[Solved] Splunk: Cannot get username when all users are selected“](/img/13/1e824c8005701e21fc5b4e73308d53.png)
[Solved] Splunk: Cannot get username when all users are selected“

世界环境日 | 周大福用心服务推动减碳环保

大话云原生之负载均衡篇-小饭馆客流量变大了

小鹏P7出事故,安全气囊未弹出,这正常吗?

分享 10 个 JS 闭包面试题(图解),进来看看你能答对多少

中国信通院、清华大学、腾讯安全,云原生安全产学研用强强联合!
随机推荐
[LeetCode] 反转字符串【344】
go 4種單例模式
解决 excel 文件上传时更改选中的文件出现错误net::ERR_UPLOAD_FILE_CHANGED
Graphic view frame
【喜欢的诗词】好了歌
[leetcode] there are duplicate elements [217]
创新实力再获认可!腾讯安全MSS获2022年度云原生安全守护先锋
[leetcode] number of palindromes [9]
剑指 Offer II 099. 最小路径之和-双百代码
PMP project integration management
odoo13搭建医院HRP环境(详细步骤)
【硬件】标准阻值的由来
杰理之内置关机电流 1.2uA,之后不能长按开机【篇】
杰理之内置短按再长按,不管长按多长时间都是短按【篇】
Learning records of data analysis (II) -- simple use of response surface method and design expert
How can I use knockout's $parent/$root pseudovariables from inside a . computed() observable?
Golang的学习路线
杰理之直接触摸样机的顶针反应不正常【篇】
xshell配置xforward转发火狐浏览器
What is the'function'keyword used in some bash scripts- What is the 'function' keyword used in some bash scripts?