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 - #渋谷JVM
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Taro Nagasawa
April 18, 2015
Programming
2.2k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Kotlin - #渋谷JVM
渋谷JVMの懇親会LT用のスライドです。Kotlinの拡張関数とNULL安全について簡単に紹介します。
Taro Nagasawa
April 18, 2015
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
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
380
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
570
JRuby: Past, Present, and Future
headius
0
210
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
360
SONY CISC-NEWS NWS-1750 + NWB-225 フレームバッファの NetBSD/news68k ドライバ実装 / OSC2026Hiroshima
tsutsui
0
150
JPUG勉強会 OSSデータベースの内部構造を理解しよう(第2回)
oga5
0
270
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
AI活用は、個人から組織へ|マルチプレイヤーエージェントハーネス「QM」の社内活用事例 / AI use is moving from individuals to orgs
rkaga
1
270
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
540
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
170
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
200
Are APIs Still Relevant in the AI Era?
soyuka
0
330
Featured
See All Featured
SEO for Brand Visibility & Recognition
aleyda
0
4.8k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
310
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
50
10k
The Cult of Friendly URLs
andyhume
79
7k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Design in an AI World
tapps
1
330
First, design no harm
axbom
PRO
2
1.3k
Side Projects
sachag
456
43k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
66k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
390
Agile that works and the tools we love
rasmusluckow
331
22k
Transcript
݄ौ୩+7. ᖒଠ!OHTX@UBSP ,PUMJO
+7.ݴޠʂ Նൃදʂ +FU#SBJOTʂ
੩తܕ͚ /6--҆શ ΦϒδΣΫτࢦ Ϋϩʔδϟ γϯϓϧ BMU+4
ࠓ͢͜ͱʂ ֦ுؔ /6--҆શ
֦ுؔ
fun main(args : Array<String>) { "world".hello() / / => Hello,
world! } ! fun String.hello() { println("Hello, ${this}!") }
/ / Kotlin fun String.hello() { println("Hello, ${this}!") } !
/ / Java static void hello(String receiver) {...}
/6--҆શ
val a: String = null / / NG val b:
String? = null / / OK /PU/VMM/VMMBCMF Λ໌֬ʹ۠ผ͢Δ
val a: String? = null a.toUpperCase() / / NG /VMMBCMFมʹ
ී௨ʹΞΫηεͰ͖ͳ͍
val a: String? = null a?.toUpperCase() / / a.map(String::toUpperCase); Ͱ҆શݺͼग़͠
Ϩγʔό͕OVMMͳΒOVMMΛฦ͚ͩ͢
val a: String? = null a ?: "" / /
a.orElse(""); ͰσϑΥϧτ
val a: String? = null a!! / / !!!Exception!!! /
/ a.get(); Ͱڧ੍/PU/VMMԽ ةݥʂݪଇېࢭʂ
֦ுؔ /6--҆શ
֦ுؔMFU͜ͳ͢ MFUඪ४ϥΠϒϥϦͷؔ w JG1SFTFOU w NBQ w qBU.BQ
w JG1SFTFOU w NBQ w qBU.BQ ,PUMJOʹWPJE ͳ͘ɺؔ ඞͣΛฦ͔͢ Βಉ͡
֦ுؔMFU͜ͳ͢ MFUඪ४ϥΠϒϥϦͷؔ
w JG1SFTFOU w NBQ w qBU.BQ ʮOVMMͷOVMMʯͱ ͍͏ೖΕࢠߏʹ ͳΒͳ͍͔Βಉ͡ ֦ுؔMFU͜ͳ͢
MFUඪ४ϥΠϒϥϦͷؔ
a?.let { a -> toInt(a) } a?.let { toInt(it) }
a?.let(::toInt) MFU༻ྫ ಉ͡ɻ ॻ͖ํ͕ҧ ͏͚ͩ
ෳͷ/VMMBCMFΛ /PU/VMMͱͯ͠ѻ͍͍ͨ
a?.let { a -> b?.let { b -> a -
b } } ͭͷ*OU B CͷҾ͖ࢉ
a?.let { a -> b?.let { b -> a -
b } } ͭͷ*OU B CͷҾ͖ࢉ ωετ ಡΈʹ͍͘
/ / Ҿ͖ࢉͷؔ ΧϦʔԽ val minus = fun(a: Int) =
fun(b: Int) = a - b ! Ҿͱͯ͠/VMMBCMFͳؔΛऔΕΔMFUతͳͭ fun <A, B> A.bind(f: ((A) -> B)?): B? = f?.invoke(this) ͭͷؔΛ༻ҙ
b?.bind(a?.bind(minus)) ωετ͕ফ͑ͨʂ
ωετ͕ফ͑ͨʂ ׅހͷରԠؔͱ͔͆ BCͳͷʹɺొ͢Δॱং͕ٯɻ ಡΈʹ͍͘ʂ b?.bind(a?.bind(minus))
fun <A, B> ((A)->B).apply(a: A?): B? = a?.bind(this) ͏Ұखؒ
minus.apply(a)?.apply(b) Ͱ͖ͨʂ NJOVT͔Βελʔτͯ͠ɺBɺC ͷॱͰهड़Ͱ͖Δʂ ϝιουνΣʔϯʹͳͬͯΔʂ
ෳࡶ ໘͍͘͞ val minus = fun(a: Int) = fun(b: Int)
= a - b fun <A, B> A.bind(f: ((A) -> B)?): B? = f?.invoke(this) fun <A, B> ((A)->B).apply(a: A?): B? = a?.bind(this)
if (a != null && b != null) a -
b else null ࣮͜Ε͚ͩͰ͓̺
࣮͜Ε͚ͩͰ͓̺ OVMMͰͳ͍͜ͱ͕อূ͞ΕΔॴͰ /VMMBCMFมΛ/PU/VMMͱͯ͠ѻ͑Δ if (a != null && b !=
null) a - b else null
·ͱΊ ֦ுؔͰศརϝιου͕ੜͤΔʂ /6--҆શ҆શͰѻ͍ํ؆୯ʂ
ࣗݾհ ᖒଠ!OHTX@UBSP ͱ͕େ͖ͳΤϯδχΞ 4PGUXBSF%FTJHO ٕධ Ͱ ,PUMJOهࣄΛ࿈ࡌத
%SPJE,BJHJ ,PUMJO"OESPJE։ൃαϙʔτ ྗೖΕͯΔײ 1MVHJOϥΠϒϥϦͳͲ ͷ%SPJE,BJHJͰൃද͠·͢
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ -FU`TFOKPZ,PUMJO