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
Kotlin Null-Safety機構について
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Taro Nagasawa
November 09, 2013
Programming
2.3k
3
Share
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.5k
Kotlin 最新動向2022 #tfcon #techfeed
ntaro
1
2.3k
#Ubie 狂気の認知施策と選考設計
ntaro
13
14k
UbieにおけるサーバサイドKotlin活用事例
ntaro
1
1.2k
KotlinでSpring 完全理解ガイド #jsug
ntaro
6
3.6k
Kotlinでサーバサイドを始めよう!
ntaro
1
1k
Androidからサーバーサイドまで!プログラミング言語 Kotlinの魅力 #devboost
ntaro
5
3k
Kotlin Contracts #m3kt
ntaro
4
4.3k
How_to_Test_Server-side_Kotlin.pdf
ntaro
1
550
Other Decks in Programming
See All in Programming
Swift Concurrency Type System
inamiy
0
530
LM Linkで(非力な!)ノートPCでローカルLLM
seosoft
0
500
How We Benchmarked Quarkus: Patterns and anti-patterns
hollycummins
1
140
JOAI2026 1st solution - heron0519 -
heron0519
0
140
Server-Side Kotlin LT大会 vol.18 [Kotlin-lspの最新情報と Neovimのlsp設定例]
yasunori0418
1
160
GitHubCopilotCLIをはじめよう.pdf
htkym
0
190
The Monolith Strikes Back: Why AI Agents ❤️ Rails Monoliths
serradura
0
340
属人化しないコード品質の作り方_2026.04.07.pdf
muraaano
0
190
iOS機能開発のAI環境と起きた変化
ryunakayama
0
180
PHPで TLSのプロトコルを実装してみるをもう一度しゃべりたい
higaki_program
0
210
PicoRuby for IoT: Connecting to the Cloud with MQTT
yuuu
2
600
NakouPAY説明用
annouim0
0
230
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
97
6.6k
Become a Pro
speakerdeck
PRO
31
5.9k
Navigating Weather and Climate Data
rabernat
0
170
YesSQL, Process and Tooling at Scale
rocio
174
15k
Between Models and Reality
mayunak
3
270
The agentic SEO stack - context over prompts
schlessera
0
750
How to Think Like a Performance Engineer
csswizardry
28
2.6k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Claude Code のすすめ
schroneko
67
220k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
370
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ίʔυͷݺͼग़͠ • !!ԋࢉࢠͷ༻
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠