Created
January 27, 2018 09:08
-
-
Save chiiia12/21aa2750f738b829b909c10c24133025 to your computer and use it in GitHub Desktop.
golang/nil check sample
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 sample struct { | |
a int | |
b string | |
} | |
func (s sample) Method() { | |
fmt.Println("Method") | |
} | |
func main() { | |
var x *sample | |
x = &sample{1, "hoge"} | |
fmt.Printf("(x==nil) is %v\n", x == nil) | |
var y *sample | |
fmt.Printf("(y==nil) is %v\n", y == nil) | |
var z MyInterface | |
z = y | |
fmt.Printf("(z==nil) is %v\n", z == nil) | |
} | |
type MyInterface interface { | |
Method() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment