当前位置:网站首页>[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 .
边栏推荐
- MPLS experiment
- Data communication and network: ch13 Ethernet
- C language: find the palindrome number whose 100-999 is a multiple of 7
- ASP. Net razor – introduction to VB loops and arrays
- Cadence physical library lef file syntax learning [continuous update]
- nn. Exploration and experiment of batchnorm2d principle
- MySQL performance optimization index
- VIM, another program may be editing the same file If this is the solution of the case
- 记一次 Showing Recent Errors Only Command /bin/sh failed with exit code 1 问题
- Introduction to random and threadlocalrandom analysis
猜你喜欢
How to realize the function of Sub Ledger of applet?
Experiment 7. IPv6
C language function
How to use "bottom logic" to see the cards in the world?
[solve the error of this pointing in the applet] SetData of undefined
I want to talk about yesterday
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
Fastlane 一键打包/发布APP - 使用记录及踩坑
C language array
轻松玩转三子棋
随机推荐
MySQL performance optimization index
A treasure open source software, cross platform terminal artifact tabby
Global and Chinese markets of NOx analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
The most robust financial products in 2022
Entitas learning [iv] other common knowledge points
轻松玩转三子棋
nn. Exploration and experiment of batchnorm2d principle
16. Memory usage and segmentation
Detailed explanation of NPM installation and caching mechanism
Globalsign's SSL certificate products
[solve the error of this pointing in the applet] SetData of undefined
Classification and application of AI chips
MPLS experiment
Lvs+kept highly available cluster
Source code analysis of the implementation mechanism of multisets in guava class library
Googgle guava ImmutableCollections
BCD code Baidu Encyclopedia
golang 设置goproxy代理的小细节,适用于go module下载超时,阿里云镜像go module下载超时
Practice of retro SOAP Protocol
Langue C: trouver le nombre de palindromes dont 100 - 999 est un multiple de 7