当前位置:网站首页>[kotlin learning] control flow of higher-order functions -- lambda return statements and anonymous functions
[kotlin learning] control flow of higher-order functions -- lambda return statements and anonymous functions
2022-07-03 09:22:00 【Android old monkey】
Control flow of higher-order function
lambda The return statement in : Returns... From a closed function
Use... In a normal loop return

Pass on to forEach Of lambda Use in return

If you are in the lambda Use in return keyword , He will From call lambda In a function that returns , Not just from lambda return . In this way return The statement is called Nonlocal return , Because it starts from a Ratio inclusion return A code block of returns... In a larger code block 了 . We can compare in java Medium for Circulation and synchronized Code block , Obviously, it will return... From the function
it is to be noted that Only in order to lambda Only when the function as a parameter is an inline function can it return from the outer function . Upper figure forEach Function body and lambda The function bodies of are inlined together , So when compiling, it is easy to return from the function containing it . In a non inline function lambda Use in return It's not allowed . A non inline function can pass to it lambda Save in variable , So that you can continue to use... After the function returns
from lambda return : Use the tag to return
Can be in lambda Use local returns in expressions ,lambda The local return in is followed by for In the loop break The expression is similar . It will end lambda Implementation , And then call lambda Execute at the code of . Distinguish Partial return and Nonlocal return , Labels need to be used . From a lambda The expression returns, and you can mark it , And then in return The key word quote This tag

To mark a lambda expression , stay lambda Put a before the curly braces label name , Then put one @ Symbol . From one lambda return , stay return Put a... After the keyword @ Symbol , Add your signature
The other is to use lambda The function name of the function as a parameter can be used as a label , such as forEach 
If you explicitly specify lambda The label of the expression , Reuse as a label has no effect , One lambda The number of labels in an expression cannot be more than one
Tagged this expression
If you bring the recipient lambda Specify the label , You can use the corresponding labeled this An expression accesses its implicit recipient

Anonymous functions : The default is to use local return

Anonymous functions look similar to normal functions

Anonymous functions and ordinary functions have the same rules for specifying the return value type , Code block Anonymous functions require Explicitly specify the return type , If you use Expression function body Can Omit Return type
Anonymous function using expression function body

In anonymous functions , Without a label return Expressions are returned from anonymous functions , Instead of returning... From a function that contains an anonymous function .
The rules :return From recent use fun The function declared by the keyword returns .lambda Not used fun keyword , therefore lambda Medium return Returns... From the outermost function , Anonymous functions use fun. Although anonymous functions look very similar to ordinary functions , But it's actually lambda Just another grammatical form of expression
At the end of the article
I have summed up some Android Core knowledge points , And some of the latest big factory interview questions 、 Knowledge brain map and video data analysis .
Needed Small partners directly click on the small card at the end of the text to receive it for free Oh , I hope we can go down together in the future .( Thank you for your support , You need to get it yourself )
Android Study PDF+ Architecture video + Interview document + Source notes
List of partial data :
- 330 page PDF Android Learning core notes ( contains 8 Large plate )


- Android The learning system corresponds to the video

- Android Advanced systems correspond to learning materials

- Android BAT Interview questions of Dachang ( With resolution )

Receiving address :

边栏推荐
- 浅谈企业信息化建设
- 精彩回顾|I/O Extended 2022 活动干货分享
- Hudi 集成 Spark 数据分析示例(含代码流程与测试结果)
- Go language - JSON processing
- 教育信息化步入2.0,看看JNPF如何帮助教师减负,提高效率?
- Wonderful review | i/o extended 2022 activity dry goods sharing
- Jenkins learning (III) -- setting scheduled tasks
- 数字化转型中,企业设备管理会出现什么问题?JNPF或将是“最优解”
- AcWing 788. 逆序对的数量
- LeetCode 513. 找树左下角的值
猜你喜欢

LeetCode 535. Encryption and decryption of tinyurl
【毕业季|进击的技术er】又到一年毕业季,一毕业就转行,从动物科学到程序员,10年程序员有话说

LeetCode 508. 出现次数最多的子树元素和

Education informatization has stepped into 2.0. How can jnpf help teachers reduce their burden and improve efficiency?

LeetCode 532. 数组中的 k-diff 数对

Vscode编辑器右键没有Open In Default Browser选项

2022-1-6 Niuke net brush sword finger offer

LeetCode 515. 在每个树行中找最大值
![[point cloud processing paper crazy reading frontier edition 13] - gapnet: graph attention based point neural network for exploring local feature](/img/66/2e7668cfed1ef4ddad26deed44a33a.png)
[point cloud processing paper crazy reading frontier edition 13] - gapnet: graph attention based point neural network for exploring local feature

LeetCode 438. 找到字符串中所有字母异位词
随机推荐
Explanation of the answers to the three questions
低代码起势,这款信息管理系统开发神器,你值得拥有!
Introduction to the basic application and skills of QT
Overview of database system
[point cloud processing paper crazy reading classic version 8] - o-cnn: octree based revolutionary neural networks for 3D shape analysis
【点云处理之论文狂读前沿版13】—— GAPNet: Graph Attention based Point Neural Network for Exploiting Local Feature
[graduation season | advanced technology Er] another graduation season, I change my career as soon as I graduate, from animal science to programmer. Programmers have something to say in 10 years
Computing level network notes
精彩回顾|I/O Extended 2022 活动干货分享
图像修复方法研究综述----论文笔记
Install third-party libraries such as Jieba under Anaconda pytorch
Crawler career from scratch (V): detailed explanation of re regular expression
In the digital transformation, what problems will occur in enterprise equipment management? Jnpf may be the "optimal solution"
【点云处理之论文狂读前沿版11】—— Unsupervised Point Cloud Pre-training via Occlusion Completion
Beego learning - JWT realizes user login and registration
数字化转型中,企业设备管理会出现什么问题?JNPF或将是“最优解”
Recommend a low code open source project of yyds
CSDN markdown editor help document
AcWing 788. 逆序对的数量
【点云处理之论文狂读前沿版9】—Advanced Feature Learning on Point Clouds using Multi-resolution Features and Learni