当前位置:网站首页>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)
}
边栏推荐
- opencv学习笔记三——图像平滑/去噪处理
- Don't stop chasing the wind and the moon. Spring mountain is at the end of Pingwu
- Explore creativity in steam art design
- 轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
- eBPF Cilium实战(1) - 基于团队的网络隔离
- Use of out covariance and in inversion in kotlin
- Caractéristiques de bisenet
- [untitled]
- [quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)
- Golang 编译约束/条件编译 ( // +build <tags> )
猜你喜欢

在Rainbond中一键部署高可用 EMQX 集群

One click installation of highly available Nacos clusters in rainbow

CCTV is so warm-hearted that it teaches you to write HR's favorite resume hand in hand

Rainbow combines neuvector to practice container safety management

拓维信息使用 Rainbond 的云原生落地实践

Basic use of CTF web shrink template injection nmap

opencv学习笔记五——梯度计算/边缘检测

Improve the delivery efficiency of enterprise products (1) -- one click installation and upgrade of enterprise applications

opencv学习笔记二——图像基本操作

Openvscode cloud ide joins rainbow integrated development system
随机推荐
Openjudge noi 2.1 1752: chicken and rabbit in the same cage
Zcmu--1492: problem d (C language)
opencv学习笔记四——膨胀/腐蚀/开运算/闭运算
Lua programming learning notes
Use of JMeter
Analysis of maker education in innovative education system
[quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)
[quick start of Digital IC Verification] 13. SystemVerilog interface and program learning
CCTV is so warm-hearted that it teaches you to write HR's favorite resume hand in hand
[quick start of Digital IC Verification] 14. Basic syntax of SystemVerilog learning 1 (array, queue, structure, enumeration, string... Including practical exercises)
[go ~ 0 to 1] obtain timestamp, time comparison, time format conversion, sleep and timer on the seventh day
发挥创客教育空间的广泛实用性
Open3D ISS关键点
提高企业产品交付效率系列(1)—— 企业应用一键安装和升级
IELTS review progress and method use [daily revision]
积分商城管理系统中应包含的四大项
Pvtv2--pyramid vision transformer V2 learning notes
Game attack and defense world reverse
Coquette data completes the cloud native transformation through rainbow to realize offline continuous delivery to customers
Wang Zijian: is the NFT of Tencent magic core worth buying?

