type field struct {
name string
}
func (p *field) print() {
fmt.Println(p.name)
}
func main1() {
data := []field{{"one"}, {"two"}, {"three"}}
for _, v := range data {
go v.print()
}
time.Sleep(3 * time.Second)
}
func main2() {
data := []*field{{"one"}, {"two"}, {"three"}}
for _, v := range data {
go v.print()
}
time.Sleep(3 * time.Second)
}
// main1输出 three three three
// main2输出 one two three
感觉像理解了,但是还是没彻底弄懂,有人能再解释下吗?
更多评论