golang包中多个init执行问题

lattle ·
尝试了下,代码如下: ``` package main import ( "fmt" "test" ) func init() { fmt.Println("1st init print in main package") } func init() { fmt.Println("2nd init print in main package") } func main() { fmt.Println("1st print in main func") fmt.Println("2nd print in main func") test.TestFunc() } ``` ``` package test import "fmt" func init() { fmt.Println("1st init print in test package") } func init() { fmt.Println("2nd init print in test package") } func TestFunc() { fmt.Println("TestFunc in test package") } ``` 多次运行,实际输出均如下: ``` 1st init print in test package 2nd init print in test package 1st init print in main package 2nd init print in main package 1st print in main func 2nd print in main func TestFunc in test package ```
#1