当前位置:网站首页>Lambda表达式:一篇文章带你通透
Lambda表达式:一篇文章带你通透
2022-07-02 22:09:00 【小趴菜学java】
一,JDK8引入Lambda表达式
JDk1.8以后接口中可以存在普通方法,不仅仅只有抽象方法,该方法是被 default 修饰的,并且该方法,他的实现子类都可以调用该方法。
在接口中定义普通方法,一般是用来修改之前版本的存在的不足。开发人员几乎使用不上。
dafault关键字在接口中表示普通方法,不能省略。

二,函数式接口:一个接口有且只有一个抽象方法,就为函数式接口。
使用@FunctionalInterface来检验是否是函数式接口,只能有一个,多了不行,少了也不行

1,通过匿名内部类,来实现函数式接口


2,Lambda表达式,来实现该接口


三,lambda表达式
Lambda表达式是基于函数是接口,如果接口中有多个或者没有接口,就不会一一对应的找到了该接口中的抽象方法。Lambda表达式就会变易出错。
只保留方法的参数和方法体的是实现。
Lambda表达式的四种形式:
1,无返回值,无参数

2,无返回值有参数

3,有返回值无参数

4,无返回值无参数
四,Lambda表达式的特点:
1,如果方法的实现只有一行代码,可以省略{}

2,若方法的参数只有一个,那么小括号可以省略
3,可以省略表达式参数的类型(要么全省略,要么全部不省略)

4,如果方法体有返回值并且方法体只有一行,可以省略{},return

边栏推荐
猜你喜欢

从2022年Q1财报看携程的韧性和远景
![[Solved] Splunk: Cannot get username when all users are selected“](/img/13/1e824c8005701e21fc5b4e73308d53.png)
[Solved] Splunk: Cannot get username when all users are selected“
![[error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')](/img/02/67448df1817e8b34b654722df8ecd4.jpg)
[error record] the flutter reports an error (could not read script 'xxx\flutter\u tools\gradle\app\u plugin\u loader.gradle')

Developers share | HLS and skillfully use Axi_ Customize the master bus interface instructions and improve the data bandwidth - area exchange speed

解决Chrome浏览器和Edeg浏览器主页被篡改的方法

Higher order operation of bits

数组进阶提高

Addition, deletion, modification and query of handwritten ORM (object relationship mapping)

【板栗糖GIS】global mapper 如何通过dsm批量制作贴地等高线

Wait to solve the zombie process
随机推荐
佩服,竟然有人把高等数学这么晦涩难懂的科目,讲解得如此通俗易懂
【板栗糖GIS】arcmap—如何批量修改注记要素的字体,颜色,大小等
php实现根据输入的年龄查询出生日期符合的数据
Data analysis learning records -- complete a simple one-way ANOVA with Excel
Go four singleton modes
U++ learning notes - relaxation
【板栗糖GIS】arcscene—如何做出有高度的高程图
`${}`的用法
Il n'est pas nécessaire d'appuyer longtemps sur la fonction de démarrage pour modifier Jelly [chapitre]
中国信通院、清华大学、腾讯安全,云原生安全产学研用强强联合!
Qt QScrollArea
Webrtc audio and video capture and playback examples and mediastream media stream analysis
Qt QScrollArea
Share 10 JS closure interview questions (diagrams), come in and see how many you can answer correctly
Jerry's charge unplugged, unable to touch the boot [chapter]
Oracle PL / SQL programming
NC50965 Largest Rectangle in a Histogram
高并发介绍及应对
傑理之修改不需要長按開機功能【篇】
Notes on key vocabulary in the English original of the biography of jobs (10) [chapter eight]