数组 – Golang:获取切片的类型
发布时间:2020-12-16 19:22:42 所属栏目:大数据 来源:网络整理
导读:我使用反射包来获取任意数组的类型,但得到 prog.go:17: cannot use sample_array1 (type []int) as type []interface {} in function argument [process exited with non-zero status] 如何从数组中获取类型?我知道如何从价值中获得它. func GetTypeArray(a
我使用反射包来获取任意数组的类型,但得到
prog.go:17: cannot use sample_array1 (type []int) as type []interface {} in function argument [process exited with non-zero status] 如何从数组中获取类型?我知道如何从价值中获得它. func GetTypeArray(arr []interface{}) reflect.Type { return reflect.TypeOf(arr[0]) } http://play.golang.org/p/sNw8aL0a5f
更改:
GetTypeArray(arr []interface{}) 至: GetTypeArray(arr interface{}) 顺便说一句,[] int不是数组而是整数切片. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |