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

边栏推荐
- Crawler career from scratch (V): detailed explanation of re regular expression
- Low code momentum, this information management system development artifact, you deserve it!
- C language programming specification
- [point cloud processing paper crazy reading classic version 9] - pointwise revolutionary neural networks
- 【点云处理之论文狂读经典版9】—— Pointwise Convolutional Neural Networks
- Data mining 2021-4-27 class notes
- LeetCode 515. Find the maximum value in each tree row
- Matlab dichotomy to find the optimal solution
- We have a common name, XX Gong
- Django operates Excel files through openpyxl to import data into the database in batches.
猜你喜欢

AcWing 788. Number of pairs in reverse order

低代码前景可期,JNPF灵活易用,用智能定义新型办公模式

State compression DP acwing 291 Mondrian's dream

Low code momentum, this information management system development artifact, you deserve it!

The "booster" of traditional office mode, Building OA office system, was so simple!

LeetCode 30. Concatenate substrings of all words
![[kotlin learning] operator overloading and other conventions -- overloading the conventions of arithmetic operators, comparison operators, sets and intervals](/img/8d/938e232c1016cabe9ee0f72be87a22.png)
[kotlin learning] operator overloading and other conventions -- overloading the conventions of arithmetic operators, comparison operators, sets and intervals

Sword finger offer II 029 Sorted circular linked list

Install third-party libraries such as Jieba under Anaconda pytorch
![[point cloud processing paper crazy reading cutting-edge version 12] - adaptive graph revolution for point cloud analysis](/img/c6/5f723d9021cf684dcfb662ed3acaec.png)
[point cloud processing paper crazy reading cutting-edge version 12] - adaptive graph revolution for point cloud analysis
随机推荐
【点云处理之论文狂读前沿版9】—Advanced Feature Learning on Point Clouds using Multi-resolution Features and Learni
Beego learning - JWT realizes user login and registration
Win10 quick screenshot
LeetCode 871. Minimum refueling times
推荐一个 yyds 的低代码开源项目
Banner - Summary of closed group meeting
[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
Pic16f648a-e/ss PIC16 8-bit microcontroller, 7KB (4kx14)
数字化转型中,企业设备管理会出现什么问题?JNPF或将是“最优解”
Explanation of the answers to the three questions
Crawler career from scratch (3): crawl the photos of my little sister ③ (the website has been disabled)
Hudi 集成 Spark 数据分析示例(含代码流程与测试结果)
【Kotlin学习】类、对象和接口——带非默认构造方法或属性的类、数据类和类委托、object关键字
LeetCode 241. Design priorities for operational expressions
AcWing 785. Quick sort (template)
In the digital transformation, what problems will occur in enterprise equipment management? Jnpf may be the "optimal solution"
Save the drama shortage, programmers' favorite high-score American drama TOP10
Severity code description the project file line prohibits the display of status error c2440 "initialization": unable to convert from "const char [31]" to "char *"
Education informatization has stepped into 2.0. How can jnpf help teachers reduce their burden and improve efficiency?
LeetCode 535. Encryption and decryption of tinyurl