1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| package main
import ( "fmt" "reflect" )
type I interface { Foo() }
type T struct{} type F struct{}
func (t T) Foo() {}
var _ I = (*T)(nil) var _ I = &T{} var _ I = new(T)
var _ I = T{}
func main() {
n1 := (*struct{})(nil) fmt.Printf("(*struct{})(nil) nil: %t ,type is: %s\n", n1 == nil, reflect.TypeOf(n1).String())
n2 := []int(nil) fmt.Printf("[]int(nil) nil: %t ,type is: %s\n", n2 == nil, reflect.TypeOf(n2).String())
n3 := map[int]bool(nil) fmt.Printf("map[int]bool(nil) nil: %t ,type is: %s\n", n3 == nil, reflect.TypeOf(n3).String())
n4 := chan string(nil) fmt.Printf("chan string(nil) nil: %t ,type is: %s\n", n4 == nil, reflect.TypeOf(n4).String())
n5 := (func())(nil) fmt.Printf("(func())(nil) nil: %t ,type is: %s\n", n5 == nil, reflect.TypeOf(n5).String())
n6 := interface{}(nil) fmt.Printf("interface{}(nil) nil: %t \n", n6 == nil)
var _ *struct{} = nil var _ []int = nil var _ map[int]bool = nil var _ chan string = nil var _ func() = nil var _ interface{} = nil
}
|