当前位置:网站首页>Go defer little knowledge
Go defer little knowledge
2022-06-25 12:36:00 【Velly_ zheng】
Without further ado , First 3 A small example
func f() (result int) {
defer func() {
result++
}()
return 2
}
//
func f2() (r int) {
t := 2
defer func() {
t = t + 1
}()
return t
}
func f3() (r int) {
defer func(r int) {
r = r + 1
}(r)
return 2
}
If you assign a value ,f1(), f2(), f3() Return respectively 3,2,2
If you want to understand , First of all, remember defer Two important features :
- defer stay return xxx After the assignment ,return Execute before empty
- defer If there is a reference , The parameter definition must be in defer Before , No. the parameter defaults to 0 Put it in
above f1() Easier to understand , because return 2 to result=2 Enter again defer function ,result++ Turned into 3, Last return, So the end result is 3
and f2() return t In fact, that is r=t, Get into defer, Changed the t Value , There is no change r Value , So the final result is 2
f3() return 2 It's actually r=2, Get into defer This is the time ,r=2 Is the result of execution , And compile time r There is no previous assignment , So the introduction defer Parameters r The default is 0, defer The medium pass parameter is 0, Internal variable with the same name r For the initial 0, Changed to 1; But internal variables with the same name r Not external f3() Return variable of r, It's just the same name
边栏推荐
- SDN system method | 9 Access network
- Learning notes 2022 overview | automatic graph machine learning, describing AGML methods, libraries and directions
- Image tagging to obtain the coordinates of the image in the ImageView
- Implementing Domain Driven Design - using the ABP framework - Summary of a series of articles
- Micro engine generates QR code
- 【数据中台】数据中台的OneID是个什么鬼,主数据它不香吗?
- 19. Implementation of MVVM architecture based on WPF event to command
- Découvrir gaussdb (pour redis): une comparaison complète avec Codis
- Mind mapping video
- Penetration tool environment -- use of cknife Chinese kitchen knife
猜你喜欢
Zhangxiaobai's way of penetration (VIII) - detailed operation steps of SQL injection - Boolean blind injection of blind injection
15. Notes on the button style of WPF
A set of automated paperless office system (oa+ approval process) source code: with data dictionary
The server reported an error 503 service unavailable:the system returned: (71) protocol error
一套自动化无纸办公系统(OA+审批流)源码:带数据字典
Total number of MySQL statistics, used and unused
20. MVVM command binding of WPF
[on]learning dynamic and hierarchical traffic spatiotemporal features with transformer
ECSHOP commodity wholesale multi attribute multi specification multi inventory batch purchase ECSHOP wholesale plug-in ECSHOP multi attribute order
Découvrir gaussdb (pour redis): une comparaison complète avec Codis
随机推荐
Spicy food advertising e-commerce system development function and spicy food advertising e-commerce app system development source code sharing
Today, I will explain to you what is DFI and its development prospects
New and old cluster migration of Minio data
Recyclerview scrolls to the specified location
ThinkPHP upload image compression size
Thinkphp3 count ` *'problem
2022 meisai topic C idea sharing + translation
Dark horse shopping mall ---2 Distributed file storage fastdfs
ECSHOP video list_ ECSHOP uploading video, video classification, video list playing video function
R language uses the scale function to scale the input data of neural network to the minimum and maximum, scale the data to between 0 and 1, and divide the data set into training set and test set
Yunfan mall -- Yunfan mall system development source code sharing
The network traceroute command is used to determine the path through which IP packets access the destination address.
A commonly used statistical modeling method -- difference analysis
Upgrade opsenssh to 8.8p1
Is it safe to open an account and buy stocks on the Internet?
Ten commandments of self-learning in machine learning
Kotlin Foundation
The R language uses the follow up The plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses stress The type parameter specifies the line type of
Time series analysis - how to use unit root test (ADF) correctly?
The difference between this and super and their respective functions