2015-10-01 20 views

回答

6

reflect.Value上沒有Slice()方法,因爲沒有對所有切片類型有效的返回值。例如,Slice() []int只適用於int分片,Slice() []string適用於字符串分片等。Slice() []interface{}也不適用,due to how the slice is stored in memory

取而代之,獲取底層切片的功能是reflect.Value.Interface()方法的一部分。

用法示例:

slice, ok := value.Interface().([]SliceElemType) 
if !ok { 
    panic("value not a []MySliceType") 
} 
+0

謝謝!正是我想要的。 –