Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Goでのレシーバーとnilの関係 / Receiver and nil relationshi...
Search
Kentaro Kawano
July 26, 2019
Programming
0
460
Goでのレシーバーとnilの関係 / Receiver and nil relationship in Go
Kentaro Kawano
July 26, 2019
Tweet
Share
More Decks by Kentaro Kawano
See All by Kentaro Kawano
Starting Python
kawaken
0
84
Goの時刻に関するテスト/Testing time in Go
kawaken
0
91
AWS Lambda + Go
kawaken
0
88
goaのdesignをラクに書く/Write goa design easily
kawaken
0
87
Goでのチーム開発とコード管理の悩み/Team development and code management in Go
kawaken
0
92
Pyvmomiとansibleのdynamic inventory
kawaken
0
93
Other Decks in Programming
See All in Programming
育てるアーキテクチャ:戦い抜くPythonマイクロサービスの設計と進化戦略
fujidomoe
1
170
Your Perfect Project Setup for Angular @BASTA! 2025 in Mainz
manfredsteyer
PRO
0
150
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
0
130
Building, Deploying, and Monitoring Ruby Web Applications with Falcon (Kaigi on Rails 2025)
ioquatix
4
1.7k
開発生産性を上げるための生成AI活用術
starfish719
3
350
Swift Concurrency - 状態監視の罠
objectiveaudio
2
490
Go Conference 2025: Goで体感するMultipath TCP ― Go 1.24 時代の MPTCP Listener を理解する
takehaya
8
1.6k
CSC509 Lecture 03
javiergs
PRO
0
330
詳しくない分野でのVibe Codingで困ったことと学び/vibe-coding-in-unfamiliar-area
shibayu36
3
4.8k
Cursorハンズオン実践!
eltociear
2
640
After go func(): Goroutines Through a Beginner’s Eye
97vaibhav
0
310
XP, Testing and ninja testing ZOZ5
m_seki
3
570
Featured
See All Featured
A designer walks into a library…
pauljervisheath
209
24k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
620
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.6k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
189
55k
A Tale of Four Properties
chriscoyier
160
23k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Making the Leap to Tech Lead
cromwellryan
135
9.6k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.7k
Git: the NoSQL Database
bkeepers
PRO
431
66k
Making Projects Easy
brettharned
119
6.4k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
Transcript
Goでのレシーバとnilの関係 2019-07-26 Umeda.go 2019 Summer Kentaro Kawano
レシーバとは • メソッド呼び出しの対象 • 値レシーバ • ポインタレシーバ
None
レシーバがnilのメソッド呼び出しはpanicになる?
None
必ずpanicになるとは限らない レシーバがnilのメソッド呼び出しはpanicになる?
メソッド式 • RecieverType.MethodName での呼び出しが可能 • user.SayHi() は (*User).SayHi(user) と同じ •
レシーバはメソッド式の第⼀引数になる
None
どんな時にpanicする?
間接参照するとき • ポインタ型の変数(値はnil)に対して • フィールドを参照するとき • 値レシーバが必要なメソッドを呼び出すとき • 変数はレシーバの型に応じて⾃動的に型が変換される
None
None
ダメな実装例
None
⼤事なところではnilチェックをちゃんとしよう
まとめ • レシーバには値レシーバとポインタレシーバがある • レシーバはメソッド式の第⼀引数 • レシーバがnilでもpanicしないケースがある • ポインタレシーバを利⽤する場合にはnilチェックする •
すべてのメソッドでチェックする必要はない(経験則