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
530
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Goでのレシーバーとnilの関係 / Receiver and nil relationship in Go
Kentaro Kawano
July 26, 2019
More Decks by Kentaro Kawano
See All by Kentaro Kawano
Starting Python
kawaken
0
150
Goの時刻に関するテスト/Testing time in Go
kawaken
0
160
AWS Lambda + Go
kawaken
0
140
goaのdesignをラクに書く/Write goa design easily
kawaken
0
130
Goでのチーム開発とコード管理の悩み/Team development and code management in Go
kawaken
0
140
Pyvmomiとansibleのdynamic inventory
kawaken
0
140
Other Decks in Programming
See All in Programming
TSX の <Hoge<Fuga>> という構文に驚いた話 / tsx-type-argument-syntax
kanaru0928
0
240
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
510
ソフトウェアラスタライザ
fadis
1
710
業務時間外もAIに働いてもらう話
colorful12
2
8.2k
Press start. Python's next generation.
willingc
PRO
3
250
ソフトウェアエンジニアにとっての生成AI - 特性を知って使い倒す / generative ai for software enginner
kishida
7
2.2k
AIに既存システムを理解させる技術 ~レガシーを見捨てないハーネスエンジニアリング入門~
ochtum
0
160
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
1
740
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
390
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
250
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
660
DynamoDBの基礎を振り返りながらベクトル検索機能を理解する
musan
2
240
Featured
See All Featured
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
290
Documentation Writing (for coders)
carmenintech
77
5.5k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
450
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Technical Leadership for Architectural Decision Making
baasie
3
540
We Have a Design System, Now What?
morganepeng
55
8.3k
Exploring anti-patterns in Rails
aemeredith
3
480
Abbi's Birthday
coloredviolet
3
9.5k
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チェックする •
すべてのメソッドでチェックする必要はない(経験則