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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Kentaro Kawano
July 26, 2019
Programming
540
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
160
Goの時刻に関するテスト/Testing time in Go
kawaken
0
170
AWS Lambda + Go
kawaken
0
150
goaのdesignをラクに書く/Write goa design easily
kawaken
0
140
Goでのチーム開発とコード管理の悩み/Team development and code management in Go
kawaken
0
140
Pyvmomiとansibleのdynamic inventory
kawaken
0
150
Other Decks in Programming
See All in Programming
Workers Cache を知る
syumai
0
340
Domain-Driven Transformation
hschwentner
2
2.3k
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
Java 27新機能 / Java 27 new features
kishida
2
200
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2k
SREの越境 / SRE Collaboration
y0hgi
2
300
プロダクトコードからライブラリの境界を見つける
elmetal
PRO
0
110
Verilogで学ぶCPU自作入門
uyuki234
8
4k
カツオ、ご期待ください
suneo3476
0
150
contenteditable と日本語入力に向き合う
colorful12
0
170
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
450
The Rails Doctrine Decade
koic
2
520
Featured
See All Featured
Utilizing Notion as your number one productivity tool
mfonobong
4
610
We Have a Design System, Now What?
morganepeng
55
8.4k
Ruling the World: When Life Gets Gamed
codingconduct
0
390
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
Accessibility Awareness
sabderemane
1
240
HDC tutorial
michielstock
2
950
Deep Space Network (abreviated)
tonyrice
0
360
Code Reviewing Like a Champion
maltzj
529
40k
How GitHub (no longer) Works
holman
316
150k
エンジニアに許された特別な時間の終わり
watany
109
250k
Mind Mapping
helmedeiros
1
390
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
580
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チェックする •
すべてのメソッドでチェックする必要はない(経験則