Skip to content

Instantly share code, notes, and snippets.

@chiiia12
Created January 27, 2018 09:08
Show Gist options
  • Save chiiia12/21aa2750f738b829b909c10c24133025 to your computer and use it in GitHub Desktop.
Save chiiia12/21aa2750f738b829b909c10c24133025 to your computer and use it in GitHub Desktop.
golang/nil check sample
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