GO learning - 007 defer


GO learning - 007 defer

先defer的先放到stack里

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package main

import "fmt"

func func1() {
fmt.Println("A")
}

func func2() {
fmt.Println("B")
}

func func3() {
fmt.Println("C")
}

func main() {
defer func1()
defer func2()
defer func3()
}

1
2
3
C
B
A

Author: Liang Junyi
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source Liang Junyi !
  TOC