0

When doing conversions to an interface is there any difference between converting from a value and converting from a pointer? Both compile and seem to function correctly. I read the spec and couldn't figure it out.


type Printer interface {
    Print()
}

type Person struct {
    Name string
}

func (x Person) Print() {
    fmt.Println(x.Name)
}

func main() {
    var x, y Printer

    x = &Person{Name: "Jim"}
    x.Print()

    y = Person{Name: "Jill"}
    y.Print()

    // How are x and y different?
}
PeterM
  • 2,060
  • 23
  • 33

0 Answers0