In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how Golang uses anonymous functions. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Two ways of using anonymous functions
First, you can use it directly when defining anonymous functions (this method can only be used once)
Package mainimport ("fmt") func main () {res1: = func (N1 int, N2 int) int {return N1 + N2} (10Power30) / / 10 fmt.Println 30 in parentheses is equivalent to a parameter list, corresponding to N1 and N2 fmt.Println ("res1=", res1)} D:\ goproject\ src\ main > go run hello.gores1= 40, respectively.
Second, assign an anonymous function to a variable (function variable), and then call the anonymous function through that variable.
Package mainimport ("fmt") func main () {/ / assign the anonymous function fun to the variable test_fun / / then the data type of test _ fun is the function type You can call test_fun: = func (N1 int, N2 int) int {return N1-N2} res2: = test_fun (10,30) res3: = test_fun (50,30) fmt.Println ("res2=", res2) fmt.Println ("res3=", res3) fmt.Printf ("% T", test_fun)} D:\ goproject\ src\ main > go run hello.gores2=-20res3 = 20func (int) via test_fun Int) int's article on "how Golang uses anonymous functions" ends here. Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.