Created
February 23, 2019 20:12
-
-
Save leosabbir/b5b8288b635682f28a4ab392b29e8492 to your computer and use it in GitHub Desktop.
Verifies that the varible accessed by defer method are evaluated only when the method is executed not 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 main() { | |
ss := &Data{"Giney"} | |
defer func () { | |
fmt.Println(ss.name) | |
}() | |
fmt.Println(ss.name) | |
ss = nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment