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.3k
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
780
Kotlin 最新動向2022 #tfcon #techfeed
ntaro
1
2.3k
#Ubie 狂気の認知施策と選考設計
ntaro
13
13k
UbieにおけるサーバサイドKotlin活用事例
ntaro
1
1.1k
KotlinでSpring 完全理解ガイド #jsug
ntaro
6
3.5k
Kotlinでサーバサイドを始めよう!
ntaro
1
1k
Androidからサーバーサイドまで!プログラミング言語 Kotlinの魅力 #devboost
ntaro
5
2.8k
Kotlin Contracts #m3kt
ntaro
4
4.2k
How_to_Test_Server-side_Kotlin.pdf
ntaro
1
520
Other Decks in Programming
See All in Programming
Signals & Resource API in Angular: 3 Effective Rules for Your Architecture @BASTA 2025 in Mainz
manfredsteyer
PRO
0
100
プログラミングどうやる? ~テスト駆動開発から学ぶ達人の型~
a_okui
0
190
プロダクト開発をAI 1stに変革する〜SaaS is dead時代で生き残るために〜 / AI 1st Product Development
kobakei
0
490
Back to the Future: Let me tell you about the ACP protocol
terhechte
0
130
(Extension DC 2025) Actor境界を越える技術
teamhimeh
1
230
クラシルを支える技術と組織
rakutek
0
190
Your Perfect Project Setup for Angular @BASTA! 2025 in Mainz
manfredsteyer
PRO
0
130
私達はmodernize packageに夢を見るか feat. go/analysis, go/ast / Go Conference 2025
kaorumuta
2
490
iOSエンジニア向けの英語学習アプリを作る!
yukawashouhei
0
180
NetworkXとGNNで学ぶグラフデータ分析入門〜複雑な関係性を解き明かすPythonの力〜
mhrtech
3
1k
複雑化したリポジトリをなんとかした話 pipenvからuvによるモノレポ構成への移行
satoshi256kbyte
1
790
10年もののAPIサーバーにおけるCI/CDの改善の奮闘
mbook
0
780
Featured
See All Featured
Producing Creativity
orderedlist
PRO
347
40k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
36
2.5k
Statistics for Hackers
jakevdp
799
220k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6.1k
Visualization
eitanlees
148
16k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.7k
Side Projects
sachag
455
43k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.6k
Balancing Empowerment & Direction
lara
4
680
Code Reviewing Like a Champion
maltzj
525
40k
Agile that works and the tools we love
rasmusluckow
331
21k
Designing Experiences People Love
moore
142
24k
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ίʔυͷݺͼग़͠ • !!ԋࢉࢠͷ༻
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠