A Tour of Go Nil slices

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 Slices: usage and internalsarticle.)

package main 
import "fmt"

func main() {
    var z []int
    fmt.Println(z, len(z), cap(z))
    if z == nil {
        fmt.Println("nil!")
    }
}

 

posted @ 2014-10-27 01:15  wuhn  阅读(152)  评论(0编辑  收藏  举报