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
540
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
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
190
fs2-io を試してたらバグを見つけて直した話
chencmd
0
240
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
440
暇に任せてProxmoxコンソール 作ってみました
karugamo
2
720
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
return文におけるstd::moveについて
onihusube
1
1.1k
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
910
Security_for_introducing_eBPF
kentatada
0
110
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
3
280
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Gamification - CAS2011
davidbonilla
80
5.1k
4 Signs Your Business is Dying
shpigford
181
21k
Six Lessons from altMBA
skipperchong
27
3.5k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Making the Leap to Tech Lead
cromwellryan
133
9k
Unsuck your backbone
ammeep
669
57k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
A Philosophy of Restraint
colly
203
16k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
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