Hello. If any concrete value has been stored in an interface value - including a nil pointer of some type - the interface will not be nil.
See this section in the FAQ for more details: https://golang.org/doc/faq#nil_error On Sunday, February 26, 2017 at 6:06:16 PM UTC+1, 장재휴 wrote: > > Hi. > > This is very simple program for testing about error type. > I found that error type casting is something strange. > I thing `err2` should be nil, but it is not nil. > Someone can explain about this result? > > https://play.golang.org/p/icjhpCCNe_ > > ---------- > > package main > > import ( > "fmt" > ) > > type MyError struct{} > > func (e MyError) Error() string { > return "MyError" > } > > func main() { > var myError *MyError = nil > if myError == nil { > fmt.Println("myError is nil") > } else { > fmt.Println("myError is not nil") > } > > var err1 error = error(nil) > if err1 == nil { > fmt.Println("err1 is nil") > } else { > fmt.Println("err1 is not nil") > } > > var err2 error = error(myError) > if err2 == nil { > fmt.Println("err2 is nil") > } else { > fmt.Println("err2 is not nil") > } > > } > > ----------- > [RESULT] > > myError is nil > err1 is nil > err2 is not nil > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.