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
Kotlin Null-Safety機構について
Search
Taro Nagasawa
November 09, 2013
Programming
2.4k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Kotlin Null-Safety機構について
JJUG CCC 2013 Fallで発表した資料
Taro Nagasawa
November 09, 2013
More Decks by Taro Nagasawa
See All by Taro Nagasawa
Android開発者のための Kotlin Multiplatform入門
ntaro
0
1.8k
Kotlin 最新動向2022 #tfcon #techfeed
ntaro
1
2.4k
#Ubie 狂気の認知施策と選考設計
ntaro
14
14k
UbieにおけるサーバサイドKotlin活用事例
ntaro
1
1.2k
KotlinでSpring 完全理解ガイド #jsug
ntaro
6
3.7k
Kotlinでサーバサイドを始めよう!
ntaro
1
1.1k
Androidからサーバーサイドまで!プログラミング言語 Kotlinの魅力 #devboost
ntaro
5
3.1k
Kotlin Contracts #m3kt
ntaro
4
4.4k
How_to_Test_Server-side_Kotlin.pdf
ntaro
1
590
Other Decks in Programming
See All in Programming
すこし踏み込む CancellationToken
htkym
2
1.5k
iOSDC2026登壇資料.pdf
riofujimon
0
200
AgentCore CLI で進化した AWS での AI エージェントの作り方 : 必要な機能を必要な時に
icoxfog417
PRO
4
400
GitHubハンズオン講座 — 実務レベルのチーム開発のフローを身につけよう
junhat6
0
110
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
240
wkhtmltopdfの次どうするか問題2026
willnet
2
1.8k
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
190
Verilogで学ぶCPU自作入門.pdf
uyuki234
7
3.8k
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
280
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
250
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
430
Java 27新機能 / Java 27 new features
kishida
2
180
Featured
See All Featured
Designing for humans not robots
tammielis
254
26k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
720
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
WENDY [Excerpt]
tessaabrams
14
40k
Bash Introduction
62gerente
615
220k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
How to build a perfect <img>
jonoalderson
1
6k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
Faster Mobile Websites
deanohume
310
32k
Transcript
Kotlin Null-Safetyػߏʹ͍ͭͯ 2013-11-09 JJUG CCC 2013 fall JVMݴޠύωϧσΟεΧογϣϯ ! ຊKotlinϢʔβάϧʔϓ
ᖒ ଠ
Α͋͘Δᷤ౻ • NullPointerException͕සൃ • NullνΣοΫ • ඞཁѱ
Nullͱ্खʹ͖߹͏ํ๏ • ϝιουγάωνϟͷ • ੩తղੳπʔϧ • ܕΛ࡞ͬͯϥοϓ
ϝιουγάωνϟͷ calc(String s) throws NPE! getNameOrNull()
੩తղੳπʔϧ calc(@NotNull String s)! @NotNull String getName()
ܕΛ࡞ͬͯϥοϓ calc(Optional<String> s)! Optional<String> getName()
͵ΔΆۦஞͰ͖ͳ͍ calc(null);
ͦ͜ͰKotlinͷ! Null-Safety
Null-Safety • NotNull, NullableΛݴޠͰαϙʔτ • Φʔόϔουͳ͠ • Nullableʹͱ͜ͱΜ৻ॏʹͳΔ • Ͱॻ͖͢͞ɺಡΈ͢͞Λҡ࣋
NotNull val name: String
NotNull val name: String = null
NotNull val name: String = null ίϯύΠϧΤϥʔʂ! ࣮ߦՄೳͳόΠτίʔυΛੜ·ͳ͍! ৗʹ҆৺ͯ͠ࢀরͰ͖Δ
NotNull val name: String = null ίϯύΠϧΤϥʔʂ! ࣮ߦՄೳͳόΠτίʔυΛੜ·ͳ͍! ৗʹ҆৺ͯ͠ࢀরͰ͖Δ Null
can not be a value of a non-null type jet.String
Nullable val name: String? = null! name.toUpperCase()
Nullable val name: String? = null! name.toUpperCase() ίϯύΠϧΤϥʔʂ! ෆҙʹΑΔNPEΛഉআ͢Δ
NullνΣοΫٛԽ val name: String? = null! if(name != null)! !
name.toUpperCase() ίϯύΠϧ௨Δ
Safe Call ↓! if(name != null) name.toUpperCase()! else null val
name: String? = null! name?.toUpperCase()
Safe Callศར val got = listOf(“foo”, null) map{! it?.toUpperCase()?.reverse()! }!
! assert(got == listOf(“OOF”, null))
Safe Callͱ૬ੑͷྑ͍ػೳ val name =! (param[“name”] as? String)?.trim()! ! person.setName(name
?: “໊ແ͠”) Safe Cast Elvis operator
NPE͕ൃੜ͢Δ໘ • throw NullPointerException()! • ֎෦Javaίʔυͷݺͼग़͠ • !!ԋࢉࢠͷ༻
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠