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を使って思った10のコト fukuoka.kt #1
Search
chocomelonchan
July 05, 2017
Programming
0
530
Kotlinを使って思った10のコト fukuoka.kt #1
chocomelonchan
July 05, 2017
Tweet
Share
More Decks by chocomelonchan
See All by chocomelonchan
アプリを最速でリリースした話 #pixiv Night 4
chocomelonchan
4
4.3k
iOSとAndroidで共通のc++のコードを使いたいけど厳しかった話
chocomelonchan
0
1.6k
droidkaigi
chocomelonchan
6
24k
potatotips16
chocomelonchan
3
2.9k
誰も話たがらない話をしたい 翻訳リソース編
chocomelonchan
2
800
Other Decks in Programming
See All in Programming
シールドクラスをはじめよう / Getting Started with Sealed Classes
mackey0225
4
640
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
2
660
ヤプリ新卒SREの オンボーディング
masaki12
0
130
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
290
Jakarta EE meets AI
ivargrimstad
0
510
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
Macとオーディオ再生 2024/11/02
yusukeito
0
370
Amazon Qを使ってIaCを触ろう!
maruto
0
400
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Become a Pro
speakerdeck
PRO
25
5k
Facilitating Awesome Meetings
lara
50
6.1k
Automating Front-end Workflow
addyosmani
1366
200k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Why Our Code Smells
bkeepers
PRO
334
57k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Agile that works and the tools we love
rasmusluckow
327
21k
Practical Orchestrator
shlominoach
186
10k
Designing for Performance
lara
604
68k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Transcript
KotlinΛͬͯࢥͬͨ10ͷίτ ࡾࢁ խن (chocomelon) 2017/0705 fukuoka.kt #1
ࣗݾհ ࡾࢁ խن (chocomelon) ωΠςΟϒΞϓϦΛओʹ୲ 2013ϐΫγϒೖࣾ Kotlinྺ 3िؒ
ฐࣾͷKotlin࠾༻ঢ়گ
pixivʢJavaʣ
pixiv ίϛοΫʢJava & Kotlinʣ
pixiv SketchʢJavaɺKotlinʹ͍ͨ͠ʣ
PawooʢJavaɺKotlinʹ͍ͨ͠ʣ
ԬͰ৽ن։ൃதͷΞϓϦ => Kotlin
ԬͰ৽ن։ൃதͷΞϓϦ ɾKotlin ɾAndroid Architecture Components ɹɾViewModel, LiveData, Room ɾDataBinding ɾRxJava/Android
KotlinΛͬͯࢥ͏10ͷίτ
1. Extension͕͢Β͍͠ fun ImageView.setImageUrl(imageUrl: String?) { if (imageUrl == null
|| !URLUtil.isValidUrl(imageUrl)) { return } Glide.with(context).load(imageUrl).into(this) }
2. ؔܕ࠷ߴ͔Α arrayOf(1, 2, 3, 4, 5) // 1, 2,
3, 4, 5 .filter { it % 2 == 0 } // 2, 4 .map {it * 2 } // 4, 8 .sum() // 12
3. σϑΥϧτҾ/͕ศར fun hoge(fugaString: String, fooInt: Int = 0, barBoolean:
= true) { // Do something } val fuga: Int = optionalVal1 ?: 5
4. when͕εϚʔτ viewModel?.getDataSourceState()?.observe(this, Observer { when (it) { DataSourceState.SUCCESS ->
infoView.setType(InfoView.Type.HIDE) DataSourceState.LOADING -> infoView.setType(InfoView.Type.LOADING) DataSourceState.EMPTY_DATA -> infoView.setType(InfoView.Type.NOTFOUND) DataSourceState.ERROR -> infoView.setType( InfoView.Type.ERROR, View.OnClickListener { reload() }) } })
5. SmartCast͕ྑ͍ fun hoge(optionalVal1: String?, optionalVal2: String?) { if (optionalVal1
!= null && optionalVal2 != null) { val hoge = optionalVal1 + optionalVal2 // Do something } } if (object is Person) { print(object.name) }
6. είʔϓ͕ؔศར class HogeActivity: AppCompatActivity() { companion object { val
BUNDLE_KEY_HOGE_INT = "HOGE_INT" fun createIntent(context: Context, hogeInt: Int): Intent = Intent(context, HogeActivity::class.java).apply { putExtra(BUNDLE_KEY_HOGE_INT, hogeInt) } } }
7. let let ͕Ϝζ͍ optionalVal1?.let { optionalVal1 -> optionalVal2?.let {
optionalVal2 -> // Do something } }
7. let let ͕Ϝζ͍ if (optionalVal1 != null || optionalVal2
!= null) { return } // Do something
7. let let ͕Ϝζ͍ optionalVal1 ?: optionalVal2 ?: return //
Do something
7. let let ͕ຊʹϜζ͍ inline fun <S, T, R> let(s:
S?, t: T?, block: (s: S?, t: T?) -> R) { if (s != null && t != null) { block(s, t) } } let(optionalVal1, optionalVal2) { optionalVal1, optionalVal2 -> // Do something }
8. Gson͍ͬͯΔ߹ҙ✋ ɾNonNullͷobjectʹNull͕ೖͬͯ͘Δ ɾύʔε࣌Θ͔Β࣮ͣߦ࣌ʹࢮ͵ ɾmoshi͓͏ https://github.com/square/moshi
9. AndroidΤϯδχΞ͕Δؾ ɾؓࢄͱͯͨ͠Slack͕Kotlinͷॻ͖ํٞ ɹͰΓ্͕Δ ɾࢼߦࡨޡָ͕͍͠ ɾ͙͢͡ΊΒΕΔ => Ұ෦Kotlinʹม͑ͯྑ͍͠ɺ ɹ ࣗಈมͦͦ͜͜༗ೳ
10. iOSͷΤϯδχΞ͕Δؾ ɾʮKotlinͩͬͨΒྑ͍Ͱ͢Αʯ ɾʮSwiftͱࣅͯΔ͡ΌΜʯ ɾʮָͦ͠͏ʢখฒʣʯ
ԬΦϑΟεͰΤϯδχΞืूத ڵຯ͕͋Δํ·ͣϥϯνͰ͠·͠ΐ͏ʂ https://www.wantedly.com/projects/90433