mirror of
https://gitee.com/shikong-sk/golang-study
synced 2025-02-25 00:12:15 +08:00
18 lines
340 B
Go
18 lines
340 B
Go
|
package main
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
func main() {
|
||
|
// 匿名函数
|
||
|
// 在函数内部 无法声明 带名称的函数
|
||
|
f1 := func(x, y int) {
|
||
|
fmt.Println("exec anonymous fun: ", x+y)
|
||
|
}
|
||
|
f1(1, 2)
|
||
|
|
||
|
// 如果只调用一次的函数 可以 简写为 立即执行函数
|
||
|
func(x, y int) {
|
||
|
fmt.Println("exec once anonymous fun: ", x+y)
|
||
|
}(5, 5)
|
||
|
}
|