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

wangyanlb · · 2950 次点击
type Person struct { Likes []string } m := map[string]Person{} sli := []string{"movie"} m["demo"] = Person{Likes: sli} logger.Debug("%v", m) 写法很多种,自己多尝试
#5
更多评论
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