Skip to content

Instantly share code, notes, and snippets.

@YuheiNakasaka
Last active August 29, 2015 14:03
Show Gist options
  • Save YuheiNakasaka/1f84789657239078fe42 to your computer and use it in GitHub Desktop.
Save YuheiNakasaka/1f84789657239078fe42 to your computer and use it in GitHub Desktop.
deferを2つ並べた場合にどちらが先に実行されるのか試し
package main
import (
"fmt"
)
func main() {
fmt.Println("スタート!")
defer fmt.Println("defer 1つめ")
defer fmt.Println("defer 2つめ")
fmt.Println("フィニッシュ!")
/*
下のdefer文から実行される
# go run defer_sample.go
スタート!
フィニッシュ!
defer 2つめ
defer 1つめ
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment