<分区>
我试过这样写:
func KeyExists(m map[interface{}]interface{}, k interface{}) bool {
if _, ok := m[k]; ok {
return true
}
return false
}
当尝试使用 m[int]int
运行它时,我得到:
cannot use xxx (type map[int]int) as type map[interface {}]interface {} in argument to KeyExists
为什么?来自:How do you make a function accept multiple types in go? 我推断 interface{} 应该在这里工作。
错误消息一半有用一半烦人,因为它指出我不能做某事但没有说明原因。