以下代码package mainimport "strings"import "fmt"type Foo stringconst ( Bar Foo = "bar" Snafu = "snafu" Foobar = "foobar")var Foos = []Foo{Bar, Snafu, Foobar}func main() { fmt.Println("Foos: " + strings.Join(Foos, ","))}产生这个错误:./test.go:17: cannot use Foos (type []Foo) as type []string in argument to strings.Join这是有道理的,因为 Foo 不是字符串,而是从字符串派生的。有没有办法在不复制的情况下将“[]Foo”强制为“[]string”?
1 回答
- 1 回答
- 0 关注
- 449 浏览
添加回答
举报
0/150
提交
取消