The zero value of a slice is nil
.
A nil slice has a length and capacity of 0.
(To learn more about slices, read the article.)
package main import "fmt"func main() { var z []int fmt.Println(z, len(z), cap(z)) if z == nil { fmt.Println("nil!") }}
本文共 312 字,大约阅读时间需要 1 分钟。
The zero value of a slice is nil
.
A nil slice has a length and capacity of 0.
(To learn more about slices, read the article.)
package main import "fmt"func main() { var z []int fmt.Println(z, len(z), cap(z)) if z == nil { fmt.Println("nil!") }}
转载于:https://www.cnblogs.com/ghgyj/p/4053321.html