当前位置:网站首页>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)
}
边栏推荐
- 轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
- Improve the delivery efficiency of enterprise products (1) -- one click installation and upgrade of enterprise applications
- 【雅思口语】安娜口语学习记录 Part3
- The largest 3 same digits in the string of leetcode simple question
- Standard function let and generic extension function in kotlin
- Give full play to the wide practicality of maker education space
- Learn how to compile basic components of rainbow from the source code
- Lua programming learning notes
- SSM 整合
- Easy to understand SSO
猜你喜欢

使用 Nocalhost 开发 Rainbond 上的微服务应用

Fast parsing intranet penetration escorts the document encryption industry

Rainbond结合NeuVector实践容器安全管理

opencv学习笔记四——膨胀/腐蚀/开运算/闭运算

Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms

归并排序和非比较排序

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

Xcit learning notes

提高企业产品交付效率系列(1)—— 企业应用一键安装和升级
![[quick start of Digital IC Verification] 13. SystemVerilog interface and program learning](/img/d8/ffc1b7527f0269cecb2946ab402a2e.png)
[quick start of Digital IC Verification] 13. SystemVerilog interface and program learning
随机推荐
opencv学习笔记五——梯度计算/边缘检测
Transformation function map and flatmap in kotlin
利用 Helm 在各类 Kubernetes 中安装 Rainbond
Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms
【雅思口语】安娜口语学习记录 Part3
Uniapp mobile terminal forced update function
Standard function let and generic extension function in kotlin
CTF-WEB shrine模板注入nmap的基本使用
【Go ~ 0到1 】 第七天 获取时间戳,时间比较,时间格式转换,Sleep与定时器
SSM 整合
opencv学习笔记二——图像基本操作
Le système mes est un choix nécessaire pour la production de l'entreprise
拓维信息使用 Rainbond 的云原生落地实践
单元测试报告成功率低
数据中台落地实施之法
The use of generics and vararg variable parameters in kotlin
Don't stop chasing the wind and the moon. Spring mountain is at the end of Pingwu
GFS distributed file system
积分商城管理系统中应包含的四大项
The truth of robot education in hands-on practice

