我如何将[]字符串作为…interface {}参数传递

问题描述 投票:0回答:1

我知道当参数为... strings时如何传递它>

但是这种情况有点不同:

func main() {
    args := []string{"hello", "world"}
    fmt.Println(args...)
}

https://play.golang.org/p/7ELdQQvdPvR

上面的代码抛出错误cannot use args (type [] string) as type [] interface {} in argument to fmt.Println

实现此目标的最惯用的方法是什么?

我知道当参数为...字符串时如何传递它,但是这种情况有些不同:func main(){args:= [] string {“ hello”,“ world”} fmt.Println(args。 ..)} https://play.golang.org/p / ...

go slice variadic
1个回答
-1
投票

这可以通过以下两种方式之一进行:

© www.soinside.com 2019 - 2024. All rights reserved.