go - How to convert interface{} to []int? -
i programming in go programming language.
say there's variable of type interface{} contains array of integers. how convert interface{} []int?
i have tried
interface_variable.([]int) the error got is:
panic: interface conversion: interface []interface {}, not []int
it's []interface{} not 1 interface{}, have loop through , convert it:
http://play.golang.org/p/r441h4fvmw
func main() { := []interface{}{1, 2, 3, 4, 5} b := make([]int, len(a)) := range { b[i] = a[i].(int) } fmt.println(a, b) }
Comments
Post a Comment