我有一个命名函数Keys()来获取地图的所有键,这里是代码:
func main() {
m2 := map[int]interface{}{
2:"string",
3:"int",
}
fmt.Println(Keys(m2))
}
func Keys(m map[interface{}]interface{}) (keys []interface{}) {
for k := range m {
keys = append(keys, k)
}
return keys
}
Run Code Online (Sandbox Code Playgroud)
但是我得到了
cannot use m2 (type map[int]interface {}) as type map[interface {}]interface {} in argument to Keys
Run Code Online (Sandbox Code Playgroud)
Go支持泛型,我该如何修复代码?