吾八哥博客

您现在的位置是:首页 > 码农手记 > Golang > 正文

Golang

golang里判断interface类型是否为nil的方法

吾八哥2020-05-29Golang1035
参考代码:// IsNil check obj of interface{} is nilfunc IsNil(ob

参考代码:

// IsNil check obj of interface{} is nil
func IsNil(obj interface{}) bool {
	vi := reflect.ValueOf(obj)
	if vi.Kind() == reflect.Ptr {
		return vi.IsNil()
	}
	return false
}