将nil [] byte变量转换为string不会感到惊慌。 为什么不?

package main

import ("fmt")

func main() {

    var bts []byte =nil
    fmt.Println("the result :", string(bts)) // why not panic ?
    // the result :
}

https://play.golang.org/p/dzRzzKvUyd

In general for any type that can be nil you can generate whatever string representation you like! It's because when implementing fmt.Stringer interface (see here) - or any function on a type that can be nil - you can have a nil for receiver value. In other words you can call methods on nil objects in contrast with OOP languages. In this sample code, you'll see ʕ◔ϖ◔ʔ hey nilo! for a nil value of the second type, but BOO DATA!!! :: Hi! :) when you have an element inside (it prints just the first element as a sample code).

And again keep in mind nil is typed in go.

Because zero value of a slice (nil) acts like a zero-length slice. E.g. you also can declare a slice variable and then append to it in a loop:

// Filter returns a new slice holding only
// the elements of s that satisfy f()
func Filter(s []int, fn func(int) bool) []int {
    var p []int // == nil
    for _, v := range s {
        if fn(v) {
            p = append(p, v)
        }
    }
    return p
}

More details can be found here: https://blog.golang.org/go-slices-usage-and-internals