当前位置:网站首页>Go语言中,函数是一种类型
Go语言中,函数是一种类型
2022-07-07 05:25:00 【码二哥】
0 grpc-go、protobuf、multus-cni 技术专栏 总入口
4 grpc、oauth2、openssl、双向认证、单向认证等专栏文章目录
总结(记住下面三句
)
1、
函数
,也是一种类型
(要特别注意
)
2、函数
,可以赋值给变量
(要特别
注意)
3、函数
,可以作为参数
,进行传递
package func5_test
import (
"testing"
"fmt"
)
//声明一个fire函数
func fire() {
fmt.Print("--->this is fire func")
}
func study(str string) {
fmt.Printf("--->I'm studying %s", str)
}
// 测试,函数是否赋值给变量
func TestFuncVariable(t *testing.T) {
// 声明变量f,类型是func类型,函数类型
// 将变量 f 声明为 func() 类型,
// 调用f的时候,实际上调用的是fire函数,此时 f 就被俗称为“回调函数”,
// 此时 f 的值为 nil
var f func()
f = fire
f()
}
// 测试,函数是否赋值给变量
func TestStudy(t *testing.T) {
st := study
st("English")
}
// 测试,函数类型是否可以作为参数进行传递
func learning(f func()) {
fmt.Printf("--->this is running func")
f()
}
func TestFuncParams(t *testing.T) {
f := fire
// 将函数作为参数进行传递
learning(f)
}
边栏推荐
- Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms
- GFS distributed file system
- 在Rainbond中一键部署高可用 EMQX 集群
- Rainbond结合NeuVector实践容器安全管理
- 漏洞复现-easy_tornado
- 柯基数据通过Rainbond完成云原生改造,实现离线持续交付客户
- IP-guard助力能源企业完善终端防泄密措施,保护机密资料安全
- Game attack and defense world reverse
- 面试题(CAS)
- Basic use of CTF web shrink template injection nmap
猜你喜欢
随机推荐
Splunk子查询模糊匹配csv中字段值为*
一种适用于应用频繁测试下快速查看Pod的日志的方法(grep awk xargs kuberctl)
Interactive book delivery - signed version of Oracle DBA work notes
Practice of combining rook CEPH and rainbow, a cloud native storage solution
BiSeNet的特点
Qinglong panel -- Huahua reading
The single value view in Splunk uses to replace numeric values with text
Vulnerability recurrence fastjson deserialization
Openjudge noi 2.1 1752: chicken and rabbit in the same cage
使用BiSeNet实现自己的数据集
Famine cloud service management script
Caractéristiques de bisenet
Infix keyword infix expression and the use of generic extension function in kotlin
Function extension, attribute extension and non empty type extension in kotlin
Qinglong panel -- finishing usable scripts
CDC (change data capture technology), a powerful tool for real-time database synchronization
What is the function of paralleling a capacitor on the feedback resistance of the operational amplifier circuit
GFS distributed file system
BiSeNet的特點
船载雷达天线滑环的使用