I got some code like this.
import (
"fmt"
)
func ShowResult(result []string) {
fmt.Println(result)
}
func main() {
result := []string{}
defer func() {
ShowResult(result)
}()
defer ShowResult(result)
result = append(result, "test")
}
And the result is:
[]
[test]
So could anyone tell me what is difference between calling a function directly and calling it in an anonymous function when defer?