当前位置:网站首页>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)
}
边栏推荐
- It's too true. There's a reason why I haven't been rich
- JS复制图片到剪切板 读取剪切板
- Practice of combining rook CEPH and rainbow, a cloud native storage solution
- Detailed explanation of apply, also, let, run functions and principle analysis of internal source code in kotlin
- PVTV2--Pyramid Vision TransformerV2学习笔记
- 打通法律服务群众“最后一公里”,方正璞华劳动人事法律自助咨询服务平台频获“点赞”
- BiSeNet的特點
- Rainbond 5.7.1 支持对接多家公有云和集群异常报警
- Don't stop chasing the wind and the moon. Spring mountain is at the end of Pingwu
- The simple problem of leetcode is to judge whether the number count of a number is equal to the value of the number
猜你喜欢

Quick analysis of Intranet penetration helps the foreign trade management industry cope with a variety of challenges

Learn how to compile basic components of rainbow from the source code

Don't stop chasing the wind and the moon. Spring mountain is at the end of Pingwu
![[quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)](/img/dc/a809f2ec5f9e85a02e68c88bdcdb5e.png)
[quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)

Obsidan之数学公式的输入

What is the function of paralleling a capacitor on the feedback resistance of the operational amplifier circuit

Pvtv2--pyramid vision transformer V2 learning notes

Analyzing the influence of robot science and technology development concept on Social Research

解读创客思维与数学课程的实际运用

解析创新教育体系中的创客教育
随机推荐
opencv学习笔记四——膨胀/腐蚀/开运算/闭运算
Using nocalhost to develop microservice application on rainbow
BiSeNet的特点
Xcit learning notes
Snyk dependency security vulnerability scanning tool
Le système mes est un choix nécessaire pour la production de l'entreprise
Wang Zijian: is the NFT of Tencent magic core worth buying?
[quick start of Digital IC Verification] 13. SystemVerilog interface and program learning
Use of out covariance and in inversion in kotlin
云原生存储解决方案Rook-Ceph与Rainbond结合的实践
Avatary's livedriver trial experience
Deit learning notes
机器人教育在动手实践中的真理
Open3D ISS关键点
Interpreting the practical application of maker thinking and mathematics curriculum
Rsync remote synchronization
Unityhub cracking & unity cracking
One click deployment of highly available emqx clusters in rainbow
Réplication de vulnérabilité - désrialisation fastjson
Vulnerability recurrence easy_ tornado

