当前位置:网站首页>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)
}
边栏推荐
- IELTS review progress and method use [daily revision]
- SSM 整合
- Open3d ISS key points
- The simple problem of leetcode is to judge whether the number count of a number is equal to the value of the number
- Ebpf cilium practice (2) - underlying network observability
- Snyk dependency security vulnerability scanning tool
- Hisense TV starts the developer mode
- Practice of implementing cloud native Devops based on rainbow library app
- Bayes' law
- Rainbond结合NeuVector实践容器安全管理
猜你喜欢
Basic use of CTF web shrink template injection nmap
[untitled]
解析机器人科技发展观对社会研究论
Lua 编程学习笔记
Practice of combining rook CEPH and rainbow, a cloud native storage solution
Avatary's livedriver trial experience
OpenVSCode云端IDE加入Rainbond一体化开发体系
Leetcode simple question: find the K beauty value of a number
Learn how to compile basic components of rainbow from the source code
JS copy picture to clipboard read clipboard
随机推荐
Use of any superclass and generic extension function in kotlin
MES system is a necessary choice for enterprise production
Analysis of maker education in innovative education system
Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms
Understanding of out covariance, in inversion and invariance in kotlin
漏洞复现-easy_tornado
解析创新教育体系中的创客教育
[IELTS speaking] Anna's oral learning records part2
The simple problem of leetcode is to judge whether the number count of a number is equal to the value of the number
buureservewp(2)
Vulnerability recurrence fastjson deserialization
Rainbond 5.6 版本发布,增加多种安装方式,优化拓扑图操作体验
Call pytorch API to complete linear regression
The reified keyword in kotlin is used for generics
单元测试报告成功率低
Rainbond 5.7.1 支持对接多家公有云和集群异常报警
Réplication de vulnérabilité - désrialisation fastjson
Unityhub cracking & unity cracking
Basic use of CTF web shrink template injection nmap
Interface as a parameter (interface callback)