Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gopl-zh ch4问题反馈 #40

Closed
wumengrong opened this issue Sep 11, 2018 · 1 comment
Closed

gopl-zh ch4问题反馈 #40

wumengrong opened this issue Sep 11, 2018 · 1 comment

Comments

@wumengrong
Copy link

译文中描述:map中所有的key都有相同的类型,所有的value也有着相同的类型,但是key和value之间可以是不同的数据类型,
这个在目前是错误的,map[string]interface{} 或者 map[interface{}]interface{} 这种就可以是的key的类型可以不同,value的类型也可以不同。

@Tigerfyj
Copy link

这个有点混淆了抽象类型与具体类型。这里如果map的定义是接受A类型,那么任何匹配A类型的数据都可以使用。对这个map而言,所有传入的数据就是抽象类型A,不关心具体类型是A1或者A2。
map[string]interface{}这样的定义产生的疑惑在于interface{}是一个高度抽象的类型,谁都可以匹配它。但字面来说,map就是只接受interface{}这个类型的。

@cch123 cch123 closed this as completed Apr 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants