Dictionary 关于Golang编程语言中的Map
我找到密码了Dictionary 关于Golang编程语言中的Map,dictionary,go,Dictionary,Go,我找到密码了 newMap := map[string]interface{}{ "string1" : 1, "string2" : "hello", "string3" : map[string]string{ "hello" : "hello there" } } 我的猜测是,如果我们使用interface for map作为值类型,那么我们可以将任何类型插入到值中,对吗?实际上,它与map没有任何特定关系。但对您的问题的回答是是。你可以在里面插入任何你想
newMap := map[string]interface{}{
"string1" : 1,
"string2" : "hello",
"string3" : map[string]string{
"hello" : "hello there"
}
}
我的猜测是,如果我们使用interface for map作为值类型,那么我们可以将任何类型插入到值中,对吗?实际上,它与map没有任何特定关系。但对您的问题的回答是
是
。你可以在里面插入任何你想要的东西
“围棋之旅”中空界面的定义
空接口可以保存任何类型的值。(每种类型至少实现零个方法。)
检查一下您尝试时会发生什么情况的示例?是的,这是准确的
interface{}
不仅在地图中代表“任何类型”。