我希望定义一个 interface{} 类型的切片,然后希望拼接所有的元素
var result string var arrs []interface{} arrs = append(arrs, 1) arrs = append(arrs, "ha") for _, v := range arrs { result += v.(string) } fmt.Println(arrs)
然后就会报错 :
panic: interface conversion: interface {} is int, not string