我有一個接受 interface{} 的函數,然后我對類型進行切換,大小寫,如果它是切片,我想遍歷元素。我遇到的問題是我在案例選擇器中不能有多個選項,例如我似乎不能有 []int, []float32 然后在值上做一個范圍。我想做的是這樣的func digestCollection(obj interface{}) ([]byte, error) { switch v := obj.(type) { case []int64, []float64: for _, values := range v { // do something with v whether its an int or float } }}但是我收到一個錯誤,說我無法迭代接口。去
- 1 回答
- 0 關注
- 111 瀏覽
添加回答
舉報
0/150
提交
取消