当前位置:网站首页>[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 .
边栏推荐
- golang 设置goproxy代理的小细节,适用于go module下载超时,阿里云镜像go module下载超时
- Unity performance optimization reading notes - Introduction (1)
- When synchronized encounters this thing, there is a big hole, pay attention!
- [Chongqing Guangdong education] National Open University spring 2019 2727 tax basis reference questions
- [data clustering] section 3 of Chapter 4: DBSCAN performance analysis, advantages and disadvantages, and parameter selection methods
- C language: the sorting problem of circle number reporting
- C語言:求100-999是7的倍數的回文數
- A few words explain redis cache penetration, breakdown, avalanche, and redis sentinel
- DVC use case (VI): Data Registry
- 昨天的事情想说一下
猜你喜欢
Ml and NLP are still developing rapidly in 2021. Deepmind scientists recently summarized 15 bright research directions in the past year. Come and see which direction is suitable for your new pit
Play Sanzi chess easily
Fastlane one click package / release app - usage record and stepping on pit
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
Single spa, Qiankun, Friday access practice
Exness: positive I win, negative you lose
Tableau makes data summary after linking the database, and summary exceptions occasionally occur.
C語言函數
DC-5 target
Hongke case study on storm impact in coastal areas of North Carolina using lidar
随机推荐
SAP ui5 date type sap ui. model. type. Analysis of the display format of date
Xshell's ssh server rejected the password, failed to skip publickey authentication, and did not register with the server
Global and Chinese markets of NOx analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
DC-5靶机
Map container
[directory] search
Star leap plan | new projects are continuously being recruited! MSR Asia MSR Redmond joint research program invites you to apply!
How to use the mongodb ID array to get multiple documents- How to get multiple document using array of MongoDb id?
Entitas learning [3] multi context system
Fly tutorial 02 advanced functions of elevatedbutton (tutorial includes source code) (tutorial includes source code)
Error: Failed to download metadata for repo ‘AppStream‘: Cannot download repomd. XML solution
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
French Data Protection Agency: using Google Analytics or violating gdpr
Kivy教程之 08 倒计时App实现timer调用(教程含源码)
Haproxy cluster
17.内存分区与分页
Iframe to only show a certain part of the page
Anti clockwise rotation method of event arrangement -- PHP implementation
R language -- readr package reads and writes data
Global and Chinese market of dental elevators 2022-2028: Research Report on technology, participants, trends, market size and share