
1 |
package main |
[]T 转 []interface{}
Can I convert a []T to an []interface{}?
Not directly, because they do not have the same representation in memory. It is necessary to copy the elements individually to the destination slice. This example converts a slice of int to a slice of interface{}:
1 |
t := []int{1, 2, 3, 4} |




近期评论