关于map的v值是结构体的一些疑问

wangyanlb · · 2961 次点击
colefan
一点点去了解这个世界
likes := make(map[string]*Person) a := &Person{} likes["a"] = a if likes["a"].Likes == nil { likes["a"].Likes = make([]string, 0) } likes["a"].Likes = append(likes["a"].Likes, "test01") likes["a"].Likes = append(likes["a"].Likes, "test02")
#6
更多评论
type Person struct { Likes []string } p := new(Person) p.Likes = append(p.Likes, "movie") logger.Debug("%v", p.Likes) result: [movie]
#1
type Person struct { Likes []string } p := Person{make([]string, 1)} p.Likes = append(p.Likes, "movie") logger.Debug("%v", p.Likes) p = Person{Likes: make([]string, 1)} p.Likes = append(p.Likes, "movie") logger.Debug("%v", p.Likes)
#2