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
AndroidでKotlinフル活用プログラミング #Kotlin_Sansan
Search
Taro Nagasawa
January 15, 2016
Programming
1
2.8k
AndroidでKotlinフル活用プログラミング #Kotlin_Sansan
AndroidでKotlin勉強会 @ Sansan で発表したスライドです。
http://connpass.com/event/22189/
Taro Nagasawa
January 15, 2016
Tweet
Share
More Decks by Taro Nagasawa
See All by Taro Nagasawa
Android開発者のための Kotlin Multiplatform入門
ntaro
0
1.2k
Kotlin 最新動向2022 #tfcon #techfeed
ntaro
1
2.3k
#Ubie 狂気の認知施策と選考設計
ntaro
13
13k
UbieにおけるサーバサイドKotlin活用事例
ntaro
1
1.2k
KotlinでSpring 完全理解ガイド #jsug
ntaro
6
3.6k
Kotlinでサーバサイドを始めよう!
ntaro
1
1k
Androidからサーバーサイドまで!プログラミング言語 Kotlinの魅力 #devboost
ntaro
5
2.9k
Kotlin Contracts #m3kt
ntaro
4
4.3k
How_to_Test_Server-side_Kotlin.pdf
ntaro
1
530
Other Decks in Programming
See All in Programming
Oxlintはいいぞ
yug1224
5
1.2k
FOSDEM 2026: STUNMESH-go: Building P2P WireGuard Mesh Without Self-Hosted Infrastructure
tjjh89017
0
130
CSC307 Lecture 02
javiergs
PRO
1
770
疑似コードによるプロンプト記述、どのくらい正確に実行される?
kokuyouwind
0
370
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
170
GISエンジニアから見たLINKSデータ
nokonoko1203
0
200
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
15
5.1k
Patterns of Patterns
denyspoltorak
0
1.3k
dchart: charts from deck markup
ajstarks
3
990
ELYZA_Findy AI Engineering Summit登壇資料_AIコーディング時代に「ちゃんと」やること_toB LLMプロダクト開発舞台裏_20251216
elyza
2
1.4k
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
180
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
290
Featured
See All Featured
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.5k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
110
Side Projects
sachag
455
43k
Designing Powerful Visuals for Engaging Learning
tmiket
0
210
Leo the Paperboy
mayatellez
4
1.4k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
34k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Fireside Chat
paigeccino
41
3.8k
SEO for Brand Visibility & Recognition
aleyda
0
4.2k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
170
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
59
42k
Transcript
AndroidでKotlin フル活用プログラミング 2016-01-15 AndroidでKotlin勉強会 @ Sansan 長澤 太郎 @ngsw_taro
自己紹介 • 長澤 太郎 @ngsw_taro • 仕事ではAndroidメイン、Java, Scala, Railsなど •
Kotlinエバンジェリスト(自称) ◦ 講演や執筆などの実績多数 • 27歳、蟹座、ビール大好き
私のブログ
アプリカティブなんとかみたいなやつ val minus = { a: Int -> { b:
Int -> a - b } } fun <T, R> T.bind(f: ((T)->R)?): R? = f?.invoke(this) y?.bind(x?.bind(minus)) fun <T, R> ((T)->R).apply(n: T?): R? = n?.bind(this) val sub: Int? = minus.apply(x)?.apply(y) http://taro.hatenablog.jp/entry/2014/04/06/144811
メソッド参照みたいなやつ val <A, B> (A.()->B).tof: (A)->B get() = { a:
A -> a.this() } listOf("a", "bb", "ccc").map(String::length.tof) http://taro.hatenablog.jp/entry/2015/02/24/215413
Extensionで なんでもするマン
AndroidでKotlin Extensionプログラミング 2016-01-15 AndroidでKotlin勉強会 @ Sansan 長澤 太郎 @ngsw_taro
RxLifecycle面倒
RxLifecycleを使う // in RxAppCompatActivity apiAccesss() .compose(bindToLifecycle<MyData>()) .subscribe { ... }
省略できないっぽい
こうしたい: 拡張関数使えばできそう // in RxAppCompatActivity apiAccesss() .bindToLifecycle() .subscribe { ...
}
こういうの作る // in RxAppCompatActivity fun <T> Observable<T>.bindToLifecycle() = compose<T>(self.bindToLifecycle()) いい感じ!
共通部品化したい
こういう提案 interface RxLifecycleFeature: ActivityLifecycleProvider { fun <T> Observable<T>.bindToLifecycle() = compose<T>(
[email protected]
())
}
使用側のアクティビティ class MyActivity: RxAppCompatActivity(), RxLifecycleFeature { fun go() { apiAccess()
.bindToLifecycle() .subscribe {...} } }
明示的Activity起動の問題
よくあるやつ: 遷移先 class TargetActivity: Activity() { companion object { fun
intent(c: Context, data: String) = Intent(c, TargetActivity::class.java) .putExtra(“data”, data) } }
よくあるやつ: 遷移元 class SourceActivity: Activity() { fun go() { val
data = “hogefuga” startActivity(TargetActivity.intent(this, data)) } }
よくあるやつ: 遷移元 class SourceActivity: Activity() { fun go() { val
data = “hogefuga” startActivity(TargetActivity.intent(this, data)) } } thisを書きたくない! 簡単には拡張関数に できなさそう...
Intent生成を遅らせる: 遷移先 class TargetActivity: Activity() { companion object { fun
intent(data: String) = { c: Context -> Intent(c, TargetActivity::class.java) .putExtra(“data”, data) } } }
Intent生成を遅らせる: 遷移先 class TargetActivity: Activity() { companion object { fun
intent(data: String) = { c: Context -> Intent(c, TargetActivity::class.java) .putExtra(“data”, data) } } } Contextを取らなくなった
Intent生成を遅らせる: 遷移先 class TargetActivity: Activity() { companion object { fun
intent(data: String) = { c: Context -> Intent(c, TargetActivity::class.java) .putExtra(“data”, data) } } } Context -> Intentな 関数を返す
イマイチな使用例: 遷移元 class SourceActivity: Activity() { fun go() { val
data = “hogefuga” startActivity(TargetActivity.intent(data)(this)) } }
よさげな使用例: 遷移元 class SourceActivity: Activity() { fun go() { val
data = “hogefuga” TargetActivity.intent(data).start() } fun ((Context)->Intent).start() { startActivity(this(applicationContext)) } }
よさげな使用例: 遷移元 class SourceActivity: Activity() { fun go() { val
data = “hogefuga” TargetActivity.intent(data).start() } fun ((Context)->Intent).start() { startActivity(this(applicationContext)) } } ここからthisが消えた
共通部品化する for 遷移先 inline fun <reified T : Activity> intentBuilder(crossinline
init: Intent.() -> Unit) = { context: Context -> Intent(context, T::class.java).apply { init() } }
共通部品を使う: 遷移先 class TargetActivity: Activity() { companion object { fun
intent(data: String) = intentBuilder<TargetActivity> { putExtra(“data”, data) } } }
共通部品化する for 遷移元 interface IntentFeature { fun startActivity(intent: Intent) fun
getApplicationContext() fun ((Context)->Intent).start() { startActivity(this(getApplicationContext())) } } インタフェースを継承するので はなく、抽象メソッドを定義して おく
共通部品を使う: 遷移元 class SourceActivity: Activity(), IntentFeature { fun go() {
val data = “hogefuga” TargetActivity.intent(data).start() } }
おまけ: M11以前 trait IntentFeature: Activity { fun ((Context)->Intent).start() { startActivity(this(getApplicationContext()))
} } 実装する側のクラスを 指定できた
Thank you, Enjoy Kotlin!