Go语言var/init/main的执行顺序
执行顺序(降序):
- var
- init
- main
大家也可以亲自动手把下面的代码复制到Go Playground上执行看看!
示例代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
输出结果如下:
main.var was initialized
main.init was called
main.main was called
执行顺序(降序):
大家也可以亲自动手把下面的代码复制到Go Playground上执行看看!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
main.var was initialized
main.init was called
main.main was called