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
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
Amazon Qを使ってIaCを触ろう!
maruto
0
410
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
340
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
230
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
Jakarta EE meets AI
ivargrimstad
0
670
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
610
Featured
See All Featured
Docker and Python
trallard
40
3.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
It's Worth the Effort
3n
183
27k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Building Adaptive Systems
keathley
38
2.3k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
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