Hacker News new | ask | show | jobs
by infogulch 3233 days ago
Nil interfaces don't necessarily panic when their methods are called, just when nil variables are dereferenced. This is because the receiver is just another argument. For example, if `i` were this implementation of LoveGoer it wouldn't panic on a nil receiver:

    type JoeLovesGo struct{}

    func (jlg *JoeLovesGo) LoveGo() {
        fmt.Printf("Joe Loves Go! jlg is %v\n", jlg)
    }
( Playground: https://play.golang.org/p/kanq_mSmaI )

Now, if this (admittedly uncommon) use-case is worth it's downsides is a different question, but that's how it's set up now.