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

wangyanlb · · 2982 次点击
type Person struct { Likes []string } m := map[string]Person{} m["demo"] = Person{Likes: []string{"movie"}} logger.Debug("%v", m) 这个意思?
#4
更多评论
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