Skip to content

Instantly share code, notes, and snippets.

@mkmik
Created June 6, 2011 20:53
Show Gist options
  • Save mkmik/1011076 to your computer and use it in GitHub Desktop.
Save mkmik/1011076 to your computer and use it in GitHub Desktop.
nil and interfaces
package main
import (
"os"
"fmt"
)
type Test struct {
Msg string
}
func (self *Test) String() string {
if self != nil {
return self.Msg
}
return "dummy"
}
func doSomething() *Test {
return nil
}
func test() os.Error {
return doSomething()
}
func main() {
err := test()
if err != nil {
fmt.Printf("Test %T %p %s\n", err, err, err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment