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 relationship in Go
Search
Kentaro Kawano
July 26, 2019
Programming
0
290
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
13
Goの時刻に関するテスト/Testing time in Go
kawaken
0
12
AWS Lambda + Go
kawaken
0
13
goaのdesignをラクに書く/Write goa design easily
kawaken
0
13
Goでのチーム開発とコード管理の悩み/Team development and code management in Go
kawaken
0
13
Pyvmomiとansibleのdynamic inventory
kawaken
0
16
Other Decks in Programming
See All in Programming
エンターテイメント業界で利用されるAWS
demuyan
0
200
1인 개발자로 행복하게 살기 - GDG 송도 헬로월드 2024
benjaminkim
1
5.6k
educure_カリキュラム生操作マニュアル.pdf
linew_official
0
460
今、知っておきたい! 生成AIエージェントの世界
elith
3
340
OpenAPIを中心に考えるAPI開発入門 / Introduction to API Development with a Focus on OpenAPI
seike460
PRO
2
110
Git Rebase
bkuhlmann
11
1.6k
雑に思考を整理する技術と効能
konifar
55
25k
SwiftUI Performance 不要なViewの再描画と更新を抑える
bigamitiongit
1
160
TYPO3 v13 – The road to LTS: What's new and new APIs
luisasofie_xoxo
0
180
デザインシステムで Tailwind CSSとCSS in JSに分散投資をしたら良かった話
fsubal
18
4.8k
入門 AWS Amplify Gen2 / Introduction to AWS Amplify Gen2
genkiogasawara
1
310
両面どころかインフラもTSでできるよ ~ 全方位TypeScriptによるプロダクト開発 ~
myfinder
9
3.2k
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
216
8.6k
Navigating Team Friction
lara
177
13k
No one is an island. Learnings from fostering a developers community.
thoeni
14
2.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
6
990
Atom: Resistance is Futile
akmur
258
25k
[RailsConf 2023] Rails as a piece of cake
palkan
22
3.9k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
226
16k
Designing the Hi-DPI Web
ddemaree
276
33k
The Mythical Team-Month
searls
215
42k
Typedesign – Prime Four
hannesfritz
36
2.1k
Web development in the modern age
philhawksworth
202
10k
KATA
mclloyd
14
12k
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チェックする •
すべてのメソッドでチェックする必要はない(経験則