Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Goでのレシーバーとnilの関係 / Receiver and nil relationshi...
Search
Kentaro Kawano
July 26, 2019
Programming
550
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
Transcript
16 slides
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チェックする •
すべてのメソッドでチェックする必要はない(経験則
More Decks by Kentaro Kawano
See All by Kentaro Kawano
Starting Python
kawaken
0
170
Goの時刻に関するテスト/Testing time in Go
kawaken
0
170
AWS Lambda + Go
kawaken
0
160
goaのdesignをラクに書く/Write goa design easily
kawaken
0
150
Goでのチーム開発とコード管理の悩み/Team development and code management in Go
kawaken
0
140
Pyvmomiとansibleのdynamic inventory
kawaken
0
160
Other Decks in Programming
See All in Programming
私なりのハーネスエンジニアリング ~独自の言語処理系の開発を通して~
seosoft
0
210
LLM 101
dalinaum
0
500
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
330
どうしても Eloquent でリポジトリパターンをやりたいんだ #phpcon_niigata / phpcon-niigata-2026
shogogg
0
350
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
170
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
180
小さなアプリを作って公開するまで
onozaty
0
180
Vue.jsで作る空間解析アプリとCapacitorプラグインのData Bridge
hal_spidernight
1
170
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
1
270
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
680
AI時代のFlutter品質設計 — アプリ品質を守るQuality Layers
omatty198
0
380
flutter_test のその先へ — Flutter アプリの LLM 機能に「評価」という品質保証を
kosukesaigusa
0
200
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
580
WENDY [Excerpt]
tessaabrams
15
41k
Test your architecture with Archunit
thirion
2
2.5k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
610
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
480
Balancing Empowerment & Direction
lara
6
1.4k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
400