package mainimport "fmt"// go 回调函数func main() { /* 高阶函数: 根据go语言函数的数据类型的特点,可以将函数作为另一个函数的参数 fun1() fun2() 将fun1函数作为fun2函数的参数: fun2函数:高阶函数 接受一个函数作为参数的参数,叫做高阶函数 fun1函数:回调函数 作为另一个函数的参数的函数,叫回调函数 */ fmt.Printf("%T\n", add) //func(int, int) int fmt.Printf("%T\n", oper) //func(int, int, func(int, int) int) int res1 := add(1, 2) fmt.Println(res1) // 3 res2 := oper(1, 2, add) fmt.Println(res2) // 3}//类型: func (int,int)intfunc add(a, b int) int { return a + b}//类型: func(int,int,func(int,int)int)intfunc oper(m, n int, fun func(int, int) int) int { //res := fun(1, 2) //return res return fun(1, 2)}
文章来源:智云一二三科技
文章标题:go 回调函数
文章地址:https://www.zhihuclub.com/5085.shtml