我在那里我定义的数组此示例代码,但它不会编译:语法错误:意外分号或换行,期待}
$ cat a.go
package f
func t() []int {
arr := [] int {
1,
2
}
return arr
}
[email protected] ~/code/go
$ go build a.go
# command-line-arguments
.\a.go:5: syntax error: unexpected semicolon or newline, expecting }
.\a.go:7: non-declaration statement outside function body
.\a.go:8: syntax error: unexpected }
但是,如果我删除它工作的新行:
$ cat a.go
package f
func t() []int {
arr := [] int {
1,
2 }
return arr
}
[email protected] ~/code/go
$ go build a.go
请问?