Last active
February 21, 2019 19:50
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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