当前位置:网站首页>[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 .
边栏推荐
- [data clustering] section 3 of Chapter 4: DBSCAN performance analysis, advantages and disadvantages, and parameter selection methods
- Guava ImmutableSet. Builder source code analysis, shift original code, complement code, reverse code review
- Iterm tab switching order
- asp. Core is compatible with both JWT authentication and cookies authentication
- [directory] search
- BCD code Baidu Encyclopedia
- I want to talk about yesterday
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
- Uva536 binary tree reconstruction tree recovery
- IPv6 experiment
猜你喜欢

JD home programmers delete databases and run away. Talk about binlog, the killer of MySQL data backup

Review of week 278 of leetcode II

nn. Exploration and experiment of batchnorm2d principle

French Data Protection Agency: using Google Analytics or violating gdpr

Experiment 7. IPv6

ArcGis利用栅格处理工具进行影像裁剪

Flet教程之 按钮控件 ElevatedButton入门(教程含源码)
![[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22](/img/e0/21367eeaeca10c0a2f2aab3a4fa1fb.jpg)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22

17.内存分区与分页

IPv6 experiment
随机推荐
Unity performance optimization reading notes - explore performance issues -profiler (2.1)
The detailed installation process of Ninja security penetration system (Ninjitsu OS V3). Both old and new VM versions can be installed through personal testing, with download sources
Kivy教程之 08 倒计时App实现timer调用(教程含源码)
Global and Chinese markets of NOx analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
Leetcode: 408 sliding window median
Fly tutorial 02 advanced functions of elevatedbutton (tutorial includes source code) (tutorial includes source code)
0x15 string
A treasure open source software, cross platform terminal artifact tabby
C语言数组
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
When to use pointers in go?
Map container
Complementary knowledge of auto encoder
Anti clockwise rotation method of event arrangement -- PHP implementation
Fastlane 一键打包/发布APP - 使用记录及踩坑
C language: find the length of string
Cadence physical library lef file syntax learning [continuous update]
Hongke case study on storm impact in coastal areas of North Carolina using lidar
【数据聚类】第四章第一节3:DBSCAN性能分析、优缺点和参数选择方法