当前位置:网站首页>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
边栏推荐
猜你喜欢
Gas station [problem analysis - > problem conversion - > greed]
大话云原生之负载均衡篇-小饭馆客流量变大了
Lambda表达式:一篇文章带你通透
数据分析学习记录(二)---响应曲面法及Design-Expert的简单使用
Hanging mirror security won four global infosec awards on rsac2022
成功改变splunk 默认URL root path
AES高級加密協議的動機闡述
数据分析学习记录--用EXCEL完成简单的单因素方差分析
性能优化----严苛模式
世界环境日 | 周大福用心服务推动减碳环保
随机推荐
解决 excel 文件上传时更改选中的文件出现错误net::ERR_UPLOAD_FILE_CHANGED
Splunk audit 的设定
【板栗糖GIS】arcmap—如何批量修改注记要素的字体,颜色,大小等
从2022年Q1财报看携程的韧性和远景
杰理之内置关机电流 1.2uA,之后不能长按开机【篇】
[leetcode] there are duplicate elements [217]
杰理之内置短按再长按,不管长按多长时间都是短按【篇】
Golang's learning route
Performance optimization - rigorous mode
杰理之样机在多次触摸后会触发关机【篇】
mysql重置密码,忘记密码,重置root密码,重置mysql密码
MySQL查询附近的数据.并按距离进行排序.
MySQL reset password, forget password, reset root password, reset MySQL password
手写ORM(对象关系映射)增删改查
Array advanced improvement
WebRTC音视频采集和播放示例及MediaStream媒体流解析
泛型与反射,看这篇就够了
JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
uniapp微信登录返显用户名和头像
分布式监控系统zabbix