Type converting slices of interfaces

后端 未结 6 1757
孤街浪徒
孤街浪徒 2020-11-22 04:04

I\'m curious why Go does\'t implicitly convert []T to []interface{} when it will implicitly convert T to interface{}. Is

6条回答
  •  忘掉有多难
    2020-11-22 04:39

    Try interface{} instead. To cast back as slice, try

    func foo(bar interface{}) {
        s := bar.([]string)
        // ...
    }
    

提交回复
热议问题