Last active
July 8, 2020 13:56
-
-
Save betandr/4e2e005c78cb756843f7e4d8b7e1343d to your computer and use it in GitHub Desktop.
An interface is only considered nil if it is not associated with an underlying value, even a nil value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type Error struct { | |
Message string | |
} | |
func (e *Error) Error() string { | |
return "an error occured" | |
} | |
func error1() error { | |
var e error | |
fmt.Println("error1: ", e == nil) | |
return e | |
} | |
func error2() error { | |
var e *Error | |
fmt.Println("error2: ", e == nil) | |
return e | |
} | |
func main() { | |
e1 := error1() | |
fmt.Println("e1: ", e1 == nil) | |
e2 := error2() | |
fmt.Println("e2: ", e2 == nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment