https://golang.org/doc/faq#nil_error

On Thu, Feb 16, 2017 at 12:38 AM, dreyk <guninalexan...@gmail.com> wrote:

> What do you expect as output of following code?
>
> package main
>
> import "fmt"
>
> type MyInterface interface {
>        GetName() string
> }
> type MyInterfaceImpl struct {
>        Name string
> }
> func (i *MyInterfaceImpl) GetName() string {
>        return i.Name
> }
> func getNilMyInterface() MyInterface {
>        return nil
> }
> func getNilMyInterfaceImpl() *MyInterfaceImpl {
>        return nil
> }
> func main() {
>        v := getNilMyInterface()
>        if v == nil {
>               if v = getNilMyInterfaceImpl(); v == nil {
>                      fmt.Println("Ok. This code is correct!")
>               } else {
>                      fmt.Println("Opsss... It's not nil")
>                      fmt.Println(v.GetName())
>               }
>        }
> }
>
>
> Check yourself  https://play.golang.org/p/PDbyjP7QcS
>
> --
> 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.
>

-- 
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.

Reply via email to