在GO中输入接口转换片
[]T
[]interface{}
T
interface{}
func foo([]interface{}) { /* do something */ }func main() { var a []string = []string{"hello", "world"} foo(a)}
go build
不能在函数参数中使用(类型[]字符串)作为类型[]接口{}
b := []interface{}(a)
无法将(类型[]字符串)转换为类型[]接口{}
b = make([]interface{}, len(a), len(a))for i := range a { b[i] = a[i]}
Qyouu
相关分类