syntax error: unexpected newline, expecting comma or }
程序会如何编译?
func main() {
fruit := []string{
"apple",
"banana",
"cherry"
}
fmt.Println(fruit)
}
就会触发上面标题的错误,原因是切片的最后一个元素cherry后面没有逗号, 在多行切片,数组或MAP中,每行必须以逗号结尾。