I tried writing this:
func KeyExists(m map[interface{}]interface{}, k interface{}) bool {
if _, ok := m[k]; ok {
return true
}
return false
}
When trying to run this with an m[int]int
, I get:
cannot use xxx (type map[int]int) as type map[interface {}]interface {} in argument to KeyExists
Why? From this: How do you make a function accept multiple types in go? I infer that interface{} should work here.
The error message is half helpful and half annoying, since it states I cannot do something but not why.