On Tue, Oct 31, 2017 at 2:25 AM, <tmp...@hotmail.com> wrote: > I found this a little bit non sequitur - if I want to call interface > function I have a perfect business to check if underlying object is not nil > before call just to avoid panic on call. Besides underlying nil in interface > may be used to signal condition for variety of types implementing this > interface, and since there is no inheritance in Go - sometimes it's the only > proper way to indicate such condition.
In Go you can call a method on nil without a panic, this means that unless you know the type you don't know if a nil value of that type is a valid value to call a method on or not. You would be making a big assumption about the type contained within the interface{} if you checked that value for nil. Of course since you don't know the type of the value inside the interface{} it might not even be a value comparable to nil, in which case should the comparison return false or panic? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.