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
490
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
110
Goの時刻に関するテスト/Testing time in Go
kawaken
0
120
AWS Lambda + Go
kawaken
0
110
goaのdesignをラクに書く/Write goa design easily
kawaken
0
110
Goでのチーム開発とコード管理の悩み/Team development and code management in Go
kawaken
0
110
Pyvmomiとansibleのdynamic inventory
kawaken
0
110
Other Decks in Programming
See All in Programming
OSSとなったswift-buildで Xcodeのビルドを差し替えられるため 自分でXcodeを直せる時代になっている ダイアモンド問題編
yimajo
3
620
2026年 エンジニアリング自己学習法
yumechi
0
140
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
21
7.4k
組織で育むオブザーバビリティ
ryota_hnk
0
180
「ブロックテーマでは再現できない」は本当か?
inc2734
0
1k
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
480
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
2.5k
CSC307 Lecture 07
javiergs
PRO
1
560
Raku Raku Notion 20260128
hareyakayuruyaka
0
350
izumin5210のプロポーザルのネタ探し #tskaigi_msup
izumin5210
1
140
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
疑似コードによるプロンプト記述、どのくらい正確に実行される?
kokuyouwind
0
390
Featured
See All Featured
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.1k
Exploring anti-patterns in Rails
aemeredith
2
250
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
60
42k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.2k
The Curse of the Amulet
leimatthew05
1
8.7k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
830
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
190
Leo the Paperboy
mayatellez
4
1.4k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
760
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Producing Creativity
orderedlist
PRO
348
40k
Darren the Foodie - Storyboard
khoart
PRO
2
2.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チェックする •
すべてのメソッドでチェックする必要はない(経験則