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

最新文章

  1. PADS Layout 颜色设置
  2. mysql [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist (转载)
  3. JAVA反编工具件安装 JD-eclipse
  4. TFS二次开发系列:二、TFS的安装
  5. 【原】web移动端常用知识点笔记
  6. 接口自动化之Postman+Newman
  7. mysql 更改自动增长字段值的重新设定
  8. 产品中 configure/cross compile的一个bug
  9. Android 和iOS中 Gesture 和 Touch
  10. toggle笔记
  11. 获取iOS应用的版本号和app名称
  12. python递归函数下不能正常使用yield
  13. CIconListBox带图标的列表框类
  14. java python oracle推断字符串是否为数字的函数
  15. Atitit.异步编程 java .net php python js 对照
  16. dotnetcore中的IOptionsSnapshot<>的自动更新原理
  17. 用户管理和su,id 命令
  18. 解决IE11安装时需要“获取更新”(IE11离线安装)
  19. Android IPC机制(三)使用AIDL实现跨进程方法调用
  20. 知识点总结:Linq和Lambda

热门文章

  1. BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第9章节--client对象模型和REST APIs概览 JavaScript
  2. HDU 3911 线段树区间合并
  3. java无依赖读取Excel文件
  4. CCNP路由实验之九 路由策略
  5. poj1062 Bellman 最短路应用
  6. 14.idea右键单击没有 svn选项处理办法
  7. 让透明div里的文字不透明
  8. BZOJ 1578 DP
  9. Codefroces A. Saitama Destroys Hotel
  10. C#解决System.Security.Cryptography.MD5.Create()调用的目标发生了异常)的问题