go语言函数作为参数传递
2024-08-31 19:27:59
go语言函数作为参数传递,目前给我的感觉几乎和C/C++一致。非常的灵活。
import "fmt"
import "time" func goFunc1(f func()) {
go f()
} func goFunc2(f func(interface{}), i interface{}) {
go f(i)
} func goFunc(f interface{}, args... interface{}) {
if len(args) > {
go f.(func(...interface{}))(args)
} else if len(args) == {
go f.(func(interface{}))(args[])
} else {
go f.(func())()
}
} func f1() {
fmt.Println("f1 done")
} func f2(i interface{}) {
fmt.Println("f2 done", i)
} func f3(args... interface{}) {
fmt.Println("f3 done", args)
} func main() {
goFunc1(f1)
goFunc2(f2, ) goFunc(f1)
goFunc(f2, "xxxx")
goFunc(f3, "hello", "world", , 3.14)
time.Sleep( * time.Second)
}
f1 done
f2 done 100
f1 done
f2 done xxxx
f3 done [[hello world 1 3.14]]
转自 http://blog.csdn.net/eclipser1987/article/details/11772539
最新文章
- PADS Layout 颜色设置
- mysql [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist (转载)
- JAVA反编工具件安装 JD-eclipse
- TFS二次开发系列:二、TFS的安装
- 【原】web移动端常用知识点笔记
- 接口自动化之Postman+Newman
- mysql 更改自动增长字段值的重新设定
- 产品中 configure/cross compile的一个bug
- Android 和iOS中 Gesture 和 Touch
- toggle笔记
- 获取iOS应用的版本号和app名称
- python递归函数下不能正常使用yield
- CIconListBox带图标的列表框类
- java python oracle推断字符串是否为数字的函数
- Atitit.异步编程 java .net php python js 对照
- dotnetcore中的IOptionsSnapshot<;>;的自动更新原理
- 用户管理和su,id 命令
- 解决IE11安装时需要“获取更新”(IE11离线安装)
- Android IPC机制(三)使用AIDL实现跨进程方法调用
- 知识点总结:Linq和Lambda
热门文章
- BEGINNING SHAREPOINT&;#174; 2013 DEVELOPMENT 第9章节--client对象模型和REST APIs概览 JavaScript
- HDU 3911 线段树区间合并
- java无依赖读取Excel文件
- CCNP路由实验之九 路由策略
- poj1062 Bellman 最短路应用
- 14.idea右键单击没有 svn选项处理办法
- 让透明div里的文字不透明
- BZOJ 1578 DP
- Codefroces A. Saitama Destroys Hotel
- C#解决System.Security.Cryptography.MD5.Create()调用的目标发生了异常)的问题