Skip to content

Instantly share code, notes, and snippets.

@leosabbir
Last active February 21, 2019 19:50
Show Gist options
  • Save leosabbir/53cfd3ca77b0d35c358c2365521fa2e3 to your computer and use it in GitHub Desktop.
Save leosabbir/53cfd3ca77b0d35c358c2365521fa2e3 to your computer and use it in GitHub Desktop.
To verify that arguments to deferred methods are evaluated at the time of defer execution
package main
import (
"fmt"
)
type Data struct {
name string
}
func (d Data) String() string {
return fmt.Sprintf("Name: %s", d.name)
}
func main() {
ss := &Data{"Giney"}
defer func (ss *Data) {
fmt.Println(ss)
}(ss)
ss = &Data{"Hermionie"}
//ss.name = "Hermionie"
fmt.Println(ss)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment