Merge branch 'main' of https://github.com/OSHMKUFA5100/lab
# Conflicts: # note/随手记/go.md
This commit is contained in:
commit
a2dbd51f35
25
go/basics/MemoryEscape/main.go
Normal file
25
go/basics/MemoryEscape/main.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
type User struct {
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUser() *User {
|
||||||
|
u := User{}
|
||||||
|
return &u
|
||||||
|
}
|
||||||
|
|
||||||
|
func ClosureFunc() func() int {
|
||||||
|
a := 1
|
||||||
|
return func() int {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func main() {
|
||||||
|
fmt.Println(NewUser())
|
||||||
|
cf:= ClosureFunc()
|
||||||
|
fmt.Println(cf())
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user