map [string] [] string和map [string] string有什么区别?

Ano*_*uin -3 dictionary go

我注意到在Go文档中包含了这个定义:

type Values map[string][]string
Run Code Online (Sandbox Code Playgroud)

我认为这是一个错误,但后来我尝试了这个代码,它编译(Playground):

包主

import "fmt"

func main() {
    type MyType map[string][]string

    foobar := make(MyType)

    fmt.Println(foobar)
}
Run Code Online (Sandbox Code Playgroud)

它在功能上是等同于map[string]string,还是有一些区别?

dm0*_*514 6

它们是不同的.一个是字符串到一个字符串片段的映射,另一个是字符串到单个字符串的映射

的[]在[]string表示切片

http://play.golang.org/p/nv7wSWW0F7

  • 在Go中,它们是[Slices](https://golang.org/ref/spec#Slice_types),与[Arrays](https://golang.org/ref/spec#Array_types)不同. (6认同)