我有一个功能:
func ReturnTuples(map_ map[interface{}]interface{}) [][]interface{} {
我试着这样打电话:
m := make(map[string]int)
m["k1"] = 7
m["k2"] = 13
fmt.Println(ReturnTuples(m))
但是我得到了
cannot use m (type map[string]int) as type map[interface {}]interface {} in argument to ReturnTuples
既然string
和int
都实现了interface{}
,它难道不应该工作吗?
我已经搜索过了,我最多只能找到Convert map[interface {}]interface {} to map[string]string,但是它不能回答为什么我不能用m
作为参数.
我还相信,如果函数的参数只有interface{}
,它也会工作,因为map[something][something]
实现了interface
,对吗?什么是最好的方法,为什么在我的情况下不起作用?