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
Taro Nagasawa
November 09, 2013
Programming
3
2.2k
Kotlin Null-Safety機構について
JJUG CCC 2013 Fallで発表した資料
Taro Nagasawa
November 09, 2013
Tweet
Share
More Decks by Taro Nagasawa
See All by Taro Nagasawa
Android開発者のための Kotlin Multiplatform入門
ntaro
0
650
Kotlin 最新動向2022 #tfcon #techfeed
ntaro
1
2.2k
#Ubie 狂気の認知施策と選考設計
ntaro
13
13k
UbieにおけるサーバサイドKotlin活用事例
ntaro
1
1.1k
KotlinでSpring 完全理解ガイド #jsug
ntaro
6
3.4k
Kotlinでサーバサイドを始めよう!
ntaro
1
970
Androidからサーバーサイドまで!プログラミング言語 Kotlinの魅力 #devboost
ntaro
5
2.7k
Kotlin Contracts #m3kt
ntaro
4
4.1k
How_to_Test_Server-side_Kotlin.pdf
ntaro
1
490
Other Decks in Programming
See All in Programming
OpenTelemetryで始めるベンダーフリーなobservability / Vendor-free observability starting with OpenTelemetry
seike460
PRO
0
160
型安全なDrag and Dropの設計を考える
yudppp
5
620
Agent Rules as Domain Parser
yodakeisuke
1
170
TSConfigからTypeScriptの世界を覗く
planck16
2
1.2k
Rethinking Data Access: The New httpResource in Angular
manfredsteyer
PRO
0
190
データと事例で振り返るDevin導入の"リアル" / The Realities of Devin Reflected in Data and Case Studies
rkaga
3
3.3k
#QiitaBash TDDでAIに設計イメージを伝える
ryosukedtomita
2
970
コードに語らせよう――自己ドキュメント化が内包する楽しさについて / Let the Code Speak
nrslib
4
430
MLOps Japan 勉強会 #52 - 特徴量を言語を越えて一貫して管理する, 『特徴量ドリブン』な MLOps の実現への試み
taniiicom
2
340
バランスを見極めよう!実装の意味を明示するための型定義 TSKaigi 2025 Day2 (5/24)
whatasoda
2
700
TVer iOSチームの共通認識の作り方 - Findy Job LT iOSアプリ開発の裏側 開発組織が向き合う課題とこれから
techtver
PRO
0
600
少数精鋭エンジニアがフルスタック力を磨く理由 -そしてAI時代へ-
rebase_engineering
0
100
Featured
See All Featured
Six Lessons from altMBA
skipperchong
28
3.8k
Building an army of robots
kneath
306
45k
Why You Should Never Use an ORM
jnunemaker
PRO
56
9.4k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Mobile First: as difficult as doing things right
swwweet
223
9.6k
Making the Leap to Tech Lead
cromwellryan
133
9.3k
Building Adaptive Systems
keathley
41
2.6k
A better future with KSS
kneath
239
17k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.4k
Navigating Team Friction
lara
185
15k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
180
53k
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ίʔυͷݺͼग़͠ • !!ԋࢉࢠͷ༻
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠