Explaining nil interface{} gotcha in Go
Read OriginalThis technical article delves into a common 'gotcha' in Go programming: why a nil pointer of a specific type (e.g., *Foo) assigned to an empty interface (interface{}) does not compare as equal to nil. It explains that an interface value is a (type, value) pair, where nil is (no type, no value), and a nil pointer is (concrete type, nil). The post includes code examples and discusses using reflection to properly check for nil pointers within interfaces.
Comments
No comments yet
Be the first to share your thoughts!
Browser Extension
Get instant access to AllDevBlogs from your browser