当前位置:网站首页>[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 .
边栏推荐
- C語言:求100-999是7的倍數的回文數
- Hongke case study on storm impact in coastal areas of North Carolina using lidar
- Iframe to only show a certain part of the page
- [solve the error of this pointing in the applet] SetData of undefined
- 2022, 6G is heating up
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
- R语言--readr包读写数据
- Servlet learning notes
- C语言:围圈报号排序问题
- Fastlane one click package / release app - usage record and stepping on pit
猜你喜欢

昨天的事情想说一下

Servlet learning notes

It's hard to hear C language? Why don't you take a look at this (V) pointer

Tableau makes data summary after linking the database, and summary exceptions occasionally occur.
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19](/img/7c/f728e88ca36524f92c56213370399b.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19

Clion configuration of opencv

ASP. Net razor – introduction to VB loops and arrays

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

When synchronized encounters this thing, there is a big hole, pay attention!

When synchronized encounters this thing, there is a big hole, pay attention!
随机推荐
The latest idea activation cracking tutorial, idea permanent activation code, the strongest in history
Understand bloomfilter in one article
Kivy tutorial 08 countdown app implements timer call (tutorial includes source code)
SAP ui5 date type sap ui. model. type. Analysis of the display format of date
ASP. Net razor – introduction to VB loops and arrays
Openssl3.0 learning 20 provider KDF
Cadence physical library lef file syntax learning [continuous update]
记一次 Showing Recent Errors Only Command /bin/sh failed with exit code 1 问题
MYCAT middleware installation and use
【Android Kotlin】lambda的返回语句和匿名函数
Global and Chinese markets for soluble suture 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets of digital PCR and real-time PCR 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL performance optimization index
Flet教程之 按钮控件 ElevatedButton入门(教程含源码)
Possible to restore a backup of SQL Server 2014 on SQL Server 2012?
《天天数学》连载57:二月二十六日
It's hard to hear C language? Why don't you take a look at this (V) pointer
Servlet learning notes
nn. Exploration and experiment of batchnorm2d principle
Fastlane 一键打包/发布APP - 使用记录及踩坑