package main
import "fmt"
func main(){
var frank map[string]string = nil
var person interface{} = frank
if person == nil {
fmt.Println("person is nil")
} else {
fmt.Println("person isn't nil")
}
}
输出:person isn't nil
原因:interface{}类型对应Iface,其定义如下:
struct Iface {
Itab* tab;
void* data;
};
其中,Itab定义如下:
struct Itab {
InterfaceType* inter;
Type* type;
Itab* link;
int32 bad;
int32 unused;
void (*fun[])(void);
};
只有当Iface的tab与data均为nil时,interface{}才等于nil
Eface用于反射,其定义如下:
struct Eface{
Type* type;
void* data;
};