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ウォークスルー
Search
Taro Nagasawa
July 04, 2014
Programming
1.9k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Kotlinウォークスルー
第2回かわいいKotlin勉強会の発表資料です
Taro Nagasawa
July 04, 2014
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
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
1.4k
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
4
690
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
220
How I Stole PSI from Android Studio - DroidKaigi2026
worker8
0
130
AI × TiDD / 2026.09.05 Redmine 大阪
tokudiro
1
170
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
250
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
0
270
JPUG勉強会 OSSデータベースの内部構造を理解しよう(第2回)
oga5
0
250
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
3k
From 6 People Classroom Meetup to 100 People Regional Conference / FOSS4G Hiroshima 2026
furukawayasuto
0
210
XHTMLが残したもの
yosuke_furukawa
PRO
2
810
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
120
Featured
See All Featured
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
500
Designing for Performance
lara
611
70k
Ruling the World: When Life Gets Gamed
codingconduct
0
330
How GitHub (no longer) Works
holman
316
150k
Designing for Timeless Needs
cassininazir
1
480
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
600
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
430
sira's awesome portfolio website redesign presentation
elsirapls
0
410
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
240
The untapped power of vector embeddings
frankvandijk
2
1.9k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Making the Leap to Tech Lead
cromwellryan
135
10k
Transcript
Kotlin ΥʔΫεϧʔ 2014-07-04 ୈ2ճ͔Θ͍͍Kotlinษڧձ ! ຊKotlinϢʔβάϧʔϓ ᖒ ଠ
Kotlinͱ • ϓϩάϥϛϯάݴޠ • JVMͰಈ͘ • JetBrains͕த৺ʹ։ൃ͍ͯ͠ΔOSS • 2011ʹൃද •
ݱόʔδϣϯ0.7
ͳͥ,PUMJOͳͷ͔ • δϟόͪΐͬͱ… • Scalaͬͯػೳ͕ଟ͍ͯ͘͠ • GroovyಈతͰ͍͠ • ͪΐ͏Ͳ͍͍ͱ͜Ζ͕ཉ͍͠ʂ
Kotlin͕ࢦ͢ͱ͜Ζ • γϯϓϧ • ҆શ • εϐʔυ ͬ͘͟Γݴ͏ͱ…
Kotlinͷಛ • ؆ܿ • ҆શ • JVMͰಈ͘ • JavaScriptʹมͰ͖Δ •
੩తܕ͚ • ΦϒδΣΫτࢦ • ؔܕϓϩάϥϛϯά
Hello World package hello fun main(args : Array<String>) { println("Hello,
world!") }
Hello World package hello fun main(args : Array<String>) { println("Hello,
world!") } ύοέʔδԼʹ ͕ؔஔ͚Δ ΤϯτϦϙΠϯτ mainؔ
Hello World package hello fun main(args : Array<String>) { println("Hello,
world!") } มͷܕ͕ޙஔ ྻ͕ δΣωϦΫε
Hello World package hello fun main(args : Array<String>) { println("Hello,
world!") } ηϛίϩϯ ෆཁ
Ϋϥε class Greeter ! val greeter = Greeter()
Ϋϥε class Greeter ! val greeter = Greeter() ࠷খͷ Ϋϥεఆٛ
Ϋϥε class Greeter ! val greeter = Greeter() ΠϯελϯεԽ newෆཁ
ܕࢦఆෆཁ: ܕਪ
Ϋϥε class Greeter(val name: String) { fun greet() { println("Hello,
$name") } }
Ϋϥε class Greeter(val name: String) { fun greet() { println("Hello,
$name") } } ϓϩύςΟ val g = Greeter(“hoge”) val name = g.name
Ϋϥε class Greeter(val name: String) { fun greet() { println("Hello,
$name") } } ϝιου ࣜ(ม)ΛຒΊࠐΊΔ
ϓϩύςΟ class User(name: String) { var name: String = name
} ! val user = User("Taro") user.name / / => "Taro"
ϓϩύςΟ class User(name: String) { var name: String = name
} ! val user = User("Taro") user.name / / => "Taro" ίϯετϥΫλ ϓϩύςΟ
ϓϩύςΟ class User(name: String) { var name: String = name
} ! val user = User("Taro") user.name / / => "Taro" ϑΟʔϧυʹ ΞΫηεͯ͠Δ෩
ΞΫηα class User(name: String) { var name: String = name
set(name: String) {$name = name } get(): String = $name }
ΞΫηα class User(name: String) { var name: String = name
set(name: String) {$name = name } get(): String = $name } Setter Getter Backing Field
Delegated Property class User(name: String) { val name: String by
Decorator(name) } ! class Decorator(val str: String) { fun get(thisRef: Any, prop:PropertyMetadata): String = "<<$str>>" }
Delegated Property class User(name: String) { val name: String by
Decorator(name) } ! class Decorator(val str: String) { fun get(thisRef: Any, prop:PropertyMetadata): String = "<<$str>>" } User#nameͷ ΞΫηε͕ҕৡ͞ΕΔ
Ԡ༻ྫ class MainActivity: Activity() { val submitButton: Button by injector()
! fun onCreate(savedInstanceState: Bundle?) { submitButton.setOnClickListener(::submit) } }
ܕ҆શ val a: Array<Int> = array(1, 2, 3) val b:
Array<Number> = a / / NG val c: Array<out Number> = a / / OK ! a[0] = 5 / / OK c[0] = 5 / / NG
ܕ҆શ val a: Array<Int> = array(1, 2, 3) val b:
Array<Number> = a / / NG val c: Array<out Number> = a / / OK ! a[0] = 5 / / OK c[0] = 5 / / NG ArrayσϑΥϧτͰ ෆม(invariant) มҐࢦఆ͕Մೳ ͜͜Ͱڞม(covariant)
ܕ҆શ val a: Array<Int> = array(1, 2, 3) val b:
Array<Number> = a / / Error val c: Array<out Number> = a / / OK ! a[0] = 5 / / OK c[0] = 5 / / NG ܕͷෆ߹Λ ͍Ͱ͘ΕΔ
એݴՕॴࢄ val a: List<Int> = listOf(1, 2, 3) val b:
List<Number> = a / / OK ———————————————————————— class List<out T> …
એݴՕॴࢄ val a: List<Int> = listOf(1, 2, 3) val b:
List<Number> = a ———————————————————————— class List<out T> … Ϋϥεͷએݴ࣌ʹ มҐࢦఆͰ͖Δ
͕ؔfirst-class val add = { (a: Int, b: Int) ->
a + b } ! add(3, 4) / / => 7
͕ؔfirst-class list.filter({ (e: Int) -> e % 2 != 0
})
͕ؔfirst-class list filter { it % 2 != 0 }
Single Abstract Method / / Java static void invoke(Runnable r)
{ r.run(); } ! / / Kotlin Sample.invoke { hoge() } RunnableͷΘΓʹ ()->UnitͳؔΛࢦఆ
ΠϯϥΠϯؔ inline fun invoke(f: ()->Unit) { f() }
ΠϯϥΠϯؔ inline fun invoke(f: ()->Unit) { f() } inlineΞϊςʔγϣϯ: ΠϯϥΠϯల։͞ΕΔ
ؔͷܕ (Ҿͷܕ)->ฦͷܕ
֦ுؔ fun String.hello() { println("Hello, $this") } ! "World".hello()
֦ுؔ + ؔΦϒδΣΫτ fun String.hello() { println("Hello, $this") } !
"World".hello()
TCO tailRecursive fun sum(ints: List<Int>, sum: Int = 0): Int
= if(ints.isEmpty()) sum else sum(ints.tail, sum + ints.first())
TCO tailRecursive fun sum(ints: List<Int>, sum: Int = 0): Int
= if(ints.isEmpty()) sum else sum(ints.tail, sum + ints.first()) tailRecursive Ξϊςʔγϣϯ
null҆શ val a: Int = null / / OK val
b: Int? = null / / NG b.toString() / / NG if(b != null) b.toString() / / OK b?.toString() / / OK
null҆શ val a: Int = null / / OK val
b: Int? = null / / NG b.toString() / / NG if(b != null) b.toString() / / OK b?.toString() / / OK if (b != null) b.toString() else null
null҆શ fun toInt(s: String): Int? fun square(n: Int): Int จࣈྻΛtoInt()Ͱʹม
ͦͷΛsquare()Ͱೋ͍ͨ͠
ෳࡶ… if(s != null) { val i = toInt(s) if(i
!= null) square(i) else null } else { null }
ศརͳؔΛಋೖ fun <T, R> T.bind(f: ((T) -> R)?): R =
f?.invoke(this)
bindΛ͏ͱΩϨΠʹͳΔ s?.bind(::toInt)?.bind(::square)
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠