当前位置:网站首页>[Android kotlin] lambda return statement and anonymous function
[Android kotlin] lambda return statement and anonymous function
2022-07-04 12:45:00 【No bald de procedural ape】
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
Last
In the field of Technology , There's no course you can take once and for all , No matter how good the course is, it can only be “ Master leads in , Cultivation depends on individuals ”.“ knowledge has no limit ” this sentence , In any field of Technology , It's not just good habits , What's more, programmers and engineers are not eliminated by the times 、 A necessary prerequisite for better opportunities and development .
** If you feel that you are inefficient in your studies , Lack of proper guidance , You can scan the code , Join us with rich resources , Let's learn from the technology circle with strong learning atmosphere !
Join us ! There are many technical giants from the front line , There are also farmers who struggle in small factories or outsourcing companies , We are committed to building an equality , High quality Android Communication circle , It doesn't have to take everyone's technology by leaps and bounds in the short term , But in the long run , Vision , pattern , The direction of long-term development is the most important .
边栏推荐
- Googgle guava ImmutableCollections
- Method of setting default items in C # ComboBox control code
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
- The solution of permission denied
- ArcGis利用栅格处理工具进行影像裁剪
- 01. Basics - MySQL overview
- Globalsign's SSL certificate products
- Daily Mathematics Series 57: February 26
- Langue C: trouver le nombre de palindromes dont 100 - 999 est un multiple de 7
- Wechat video Number launches "creator traffic package"
猜你喜欢
DVWA range exercise 4
C fonctions linguistiques
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 24
Hongke case study on storm impact in coastal areas of North Carolina using lidar
13、 C window form technology and basic controls (3)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
DC-5 target
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
Abnormal mode of ARM processor
Source code analysis of the implementation mechanism of multisets in guava class library
随机推荐
Understand bloomfilter in one article
Unity performance optimization reading notes - Introduction (1)
17.内存分区与分页
How to use "bottom logic" to see the cards in the world?
MYCAT middleware installation and use
C语言:围圈报号排序问题
R语言--readr包读写数据
I want to talk about yesterday
Tableau makes data summary after linking the database, and summary exceptions occasionally occur.
Introduction to random and threadlocalrandom analysis
Interview question MySQL transaction (TCL) isolation (four characteristics)
Play Sanzi chess easily
C language function
Introduction to the button control elevatedbutton of the fleet tutorial (the tutorial includes the source code)
IIS error, unable to start debugging on the webserver
Lvs+kept highly available cluster
Global and Chinese market of ice water machines 2022-2028: Research Report on technology, participants, trends, market size and share
Argminer: a pytorch package for processing, enhancing, training, and reasoning argument mining datasets
mm_ Cognition of struct structure
BCD code Baidu Encyclopedia