> 文档中心 > Golang中的函数类型

Golang中的函数类型

Golang中的函数类型Demo

package testimport ("fmt")//函数类型作为返回值func GetFunc() func() {return func() {fmt.Println("函数类型作为返回值")}}//函数类型作为参数func PrintType(f func()) {fmt.Printf("f type : %T", f)f()}

主函数测试

package mainimport ("test1/test")/* * @Author: zhaojl * @Date: 2022-06-11 15:58:48 * @LastEditTime: 2022-06-12 22:47:57 * @LastEditors: zhaojl * @Description: * @FilePath: \test1\main.go */func main() {//函数类型作为返回值f := test.GetFunc()f()//函数类型作为参数test.PrintType(func() {})}