Type converting slices of interfaces

后端 未结 6 1604
孤街浪徒
孤街浪徒 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

    Convert interface{} into any type.

    Syntax:

    result := interface.(datatype)
    

    Example:

    var employee interface{} = []string{"Jhon", "Arya"}
    result := employee.([]string)   //result type is []string.
    

提交回复
热议问题