本问题已经有最佳答案,请猛点这里访问。

filepath.Join方法接受一个...string参数,但是我想传递一个[]string。当我尝试这样做时,出现以下错误:

1
cannot use append(elems, spadePath) (type []string) as type string in argument to filepath.Join

有没有一种方法可以在[] type和... type之间进行转换?


通过将...作为参数传递时,将...附加到切片中,找到了一种方法。

例如,我最初试图调用产生以下错误的以下调用:

1
filepath.Join(append(elems, basePath))

但是我通过在参数中附加...来纠正它:

1
filepath.Join(append(elems, basePath)...)
  • 这确实有效-非常感谢!!