method gets copy of struct



examples/method-gets-copy/method_gets_copy.go
package main

import "fmt"

type aPerson struct {
    name string
}

func (p aPerson) changeName(newName string) {
    fmt.Printf("Old name: %v\n", p.name)
    p.name = newName
    fmt.Printf("New name: %v\n", p.name)
}

func main() {
    joe := aPerson{name: "Joe"}
    fmt.Println(joe)
    joe.changeName("Jane")
    fmt.Println(joe)
}

examples/method-gets-copy/method_gets_copy.out
{Joe}
Old name: Joe
New name: Jane
{Joe}