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
開発 4 年目のアプリへの Kotlin 導入
Search
Ryutaro Miyashita
July 12, 2017
Programming
1
2.6k
開発 4 年目のアプリへの Kotlin 導入
2017/07/12 Kotlin 開発 Tech Talks
Ryutaro Miyashita
July 12, 2017
Tweet
Share
More Decks by Ryutaro Miyashita
See All by Ryutaro Miyashita
Java で書かれた Android アプリを Kotlin で書き直すまでの話 / Talk of rewrite Android app for Java to Kotlin
ryugoo
0
1.6k
開発 4 年目のアプリへの Kotlin 導入
ryugoo
0
400
チーム開発と Android アプリの構成
ryugoo
5
1.1k
Either で想定内のエラーと想定外のエラーを別ものにしたい!
ryugoo
2
1.6k
全て S になる -RxJava と LWS を持ち込む楽しさ-
ryugoo
4
720
Transition at RxJava 1.x to 2.x
ryugoo
0
520
Kotlin さんと誕生日が近いだけの男の話
ryugoo
2
500
Android エンジニアになって 2 年の学び
ryugoo
1
2.6k
年末だしお掃除をしよう!
ryugoo
0
770
Other Decks in Programming
See All in Programming
useSyncExternalStoreを使いまくる
ssssota
5
950
HTTP compression in PHP and Symfony apps
dunglas
2
1.6k
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
310
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
220
PaaSとSaaSの境目で信頼性と開発速度を両立する 〜TROCCO®︎のこれまでとこれから〜
gtnao
6
7.6k
103 Early Hints
sugi_0000
1
160
N.E.X.T LEVEL
pluu
2
290
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4k
Zoneless Testing
rainerhahnekamp
0
110
物流システムにおけるリファクタリングとアーキテクチャの再構築 〜依存関係とモジュール分割の重要性〜
deeprain
1
1.1k
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
160
Java 23の概要とJava Web Frameworkの現状 / Java 23 and Java web framework
kishida
2
390
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
65
4.5k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Unsuck your backbone
ammeep
669
57k
The World Runs on Bad Software
bkeepers
PRO
65
11k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Designing for Performance
lara
604
68k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Scaling GitHub
holman
458
140k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Transcript
涪䎃湡ך،فٔפך,PUMJO㼪Ⰵ
㹧♴畆㣐龤 $IBU8PSL吳䒭⠓爡 ،فٔ؛٦ءّٝ涪鿇ث٦ئ٦ت٦ !SZVHPP@
$IBU8PSLחאְג
$IBU8PSL 㕂欵ךؽآطأثٍحز؟٦ؽأ 䎃剢ַ䲿⣘㨣 㼪Ⰵ爡侧 爡 䎃剢劣傈儗挿
䎃劣ח4DBMB㼪Ⰵ 1)1⢘欽׃גְֹתׅ
ؒٝآص،꧊⚥ J04"OESPJEؒٝآص،꧊⚥ 匌❨ؔؿ؍أ㣐ꢻؔؿ؍أ 匌❨ؔؿ؍أכ剢ח匌❨ةٙ٦לח獳鯄 IUUQDPSQDIBUXPSLDPNKBSFDSVJUFOHJOFFS
$IBU8PSLךٌغ؎ٕ،فٔ 剑ⴱכ5JUBOJVN醡 +BWB4DSJQUדط؎ذ؍ـ6*䭯א،فָٔ⡲ 3FBDU/BUJWFְזװאך饥 "OESPJE晛
䎃剢ַط؎ذ؍ـ⻉ J04晛 䎃剢ַط؎ذ؍ـ⻉
䎃剢 ➂ד"OESPJEط؎ذ؍ـ晛ך涪㨣 䎃剢 ,PUMJO⹈䓼⠓ח겣⳿ׅ 䎃剢
"OESPJEط؎ذ؍ـ晛ٔٔ٦أ 䎃 せ̔せ⡤ⵖח 䎃剢 ,PUMJO醡ך傈㜠،فٔ爡ⰻ麊欽㨣 䎃剢 ,PUMJOفٗتؙءّٝח㼪Ⰵ
ז,PUMJO㼪Ⰵׅךַ
,PUMJO㼪Ⰵ䚈ּ䗳銲כַ֮ 䚈ָזֽלזזְ椚歋כזְ ,PUMJOׄׯזְה"OESPJE،فָٔ⡲זֻז ˘˘ֽדכזְ ֻ֮תדⰕ䒭؟ه٦ز鎉铂ָ㟓ִֽ ؟ه٦زָ竰竲ׁ㸜䗰䠬䩛חⰅ
ד,PUMJO㼪Ⰵׅ椚歋 ؒٝآص،涸ז嚂׃ׁ 倜׃ְךח鍗ٌثك٦ءّٝ ؒٝسِ٦ؠ٦ךًٔحزחז鎉铂堣腉 涪ח꧊⚥׃װְׅ
ن؎ٓ٦فٖ٦ز㼰זֻדֹ 膷ⰻךⳢ椚؎ً٦آ؝٦سח僥׃װְׅ "OESPJE涪鎉铂ה׃גⰕ䒭ח؟ه٦ز 涪ך䩛ָ姺תג׃תֲ〳腉䚍ָ嶊ִ
,PUMJOך㴍׃ְהֿ
ن؎ٓ٦فٖ٦ز幾ֿׅהָדֹ -BNCEB䒭 ًاحسאֽ䭯א؎ٝة٦ؿؑ٦أ 4JOHMF"CTUSBDU.FUIPE5ZQF -BNCEB䒭⢪גⱔꞿז鎸鶢ָ♶銲חז
+BWBךךה嫰鯰׃ג 䒷侧ָאד♶銲ז㜥さכ剅ַזֻג葺ְ ⢪זְ䒷侧כˑ@˒ד邌植 وآحؙؗ٦ٙ٦سˑJU˒
Button b = (Button) findViewById(R.id.button); b.setOnClickListener(new View.OnClickListener() { @Override public
void onClick(View view) { // Your business logic } }); "OESPJE+BWB %FGBVMU ⼡せؙٓأ⢪גٔأش٦إحزׅךדن؎ٓ٦فٖ٦زָ㢳ְ
Button b = (Button) findViewById(R.id.button); b.setOnClickListener(view —> { // Your
business logic }); "OESPJE+BWB -BNCEB 4JOHMF"CTUSBDU.FUIPEכ-BNCEB䒭⢪ֲֿהדأحؗٔה剅ֽ
val b = findViewById(R.id.button) as Button b.setOnClickListener { view ->
// Your business logic } b.setOnClickListener { _ -> // No use args } b.setOnClickListener { //“it” is View } ,PUMJO ,PUMJOדずׄ״ֲח剅ֽ ⢪זְ䒷侧כ@ד邌ׅ 䒷侧ָאזל ˑJU˒ؗ٦ٙ٦سד撑 ֿׅהדֹ
䙼罋僥׃װְׅ鎉铂堣腉 أ؝٦فꟼ侧 知患ז鎸鶢ך䩛⸔ֽ׃גֻ ؎ً٦آ鸐ך؎ٝأةٝأך欰䧭ח⤑ⵃ 䭁䓸ꟼ侧
ְאךⳢ椚ًاحسך״ֲח䪔ִ 傀㶷ךؙٓأח،سنحؙחًاحس鷄⸇ JG䒭 USZ䒭 XIFO䒭 ⦼鵤ֿׅהָדֹ
public static MyFragment newInstance(String str) { MyFragment fragment = new
MyFragment(); Bundle args = fragment.getArguments(); if (args == null) { args = new Bundle(); } args.putString(KEY_TEXT, str); fragment.setArguments(args); return fragment; } +BWB 葺ֻ֮ؿ؋ؙزٔػة٦ٝ
,PUMJO أ؝٦فꟼ侧 fun newInstance(str: String) = MyFragment().apply { arguments =
(arguments ?: Bundle()).apply { putString(KEY_TEXT, str) } } ˑBQQMZ˒כٖء٦غ「ֽ《גٖء٦غ鵤ׅ ➭חMFU SVO XJUI BMTPָ֮䕵ⶴָ殯ז
,PUMJO أ؝٦فꟼ侧 var test: String? = null var result: String
= text ?: run { // Some processing "Hello, world" } ٕؒؽأ怴皾㶨ה穈さׇג䊩鴟ָOVMMך㜥さך⦼ ⡦ַךⳢ椚ה穈さׇג《䖤דֹ ˟+BWB4DSJQUך⽯儗ꟼ侧䠬鋙
+BWB public class StringUtils { public static boolean isNothing(String text)
{ return text == null || text.isEmpty(); } } OVMMתכ瑞俑㶵ַוֲַثؑحؙ׃ְ
,PUMJO DMBTT PCKFDU class StringUtils { companion object { fun
isNothing(text: String?): Boolean { return text == null || text.isEmpty() } } } object StringUtils { fun isNothing(text: String?): Boolean { return text == null || text.isEmpty() } } TUBUJDًاحسך״ֲח鋅ׇ ˑPCKFDU˒⢪גءؚٕٝزٝד㹀纏ׅ
,PUMJO 䭁䓸ꟼ侧 fun String.isNothing(): Boolean = this == null ||
this.isEmpty() var test: String? = null test.isNothing() // true 㢌侧ך⚥魦ָˑOVMM˒ד/1&搀׃חثؑحָؙדֹ
תכծؽٕز؎ׁٝגְך⢪ֲ @kotlin.internal.InlineOnly public inline fun CharSequence?.isNullOrEmpty(): Boolean = this ==
null || this.length == 0 俑㶵ךOVMMתכˑ瑞˒俑㶵ثؑحָؙדֹ @kotlin.internal.InlineOnly public inline fun CharSequence?.isNullOrBlank(): Boolean = this == null || this.isBlank() 俑㶵ךOVMMתכˑ瑞涯˒俑㶵ثؑحָؙדֹ
+BWB JG俑 String text = "This is java"; String result;
if (text.length % 2 == 0) { result = "Even"; } else { result = "Odd"; } JGˑ俑˒ 㢌侧㹀纏ךة؎ىؚٝד ⦼然㹀דֹזְ
,PUMJO JG䒭 val text = "This is Kotlin" val result
= if (text.length % 2 == 0) { "Even" } else { "Odd" } JGˑ䒭˒ה׃ג⦼鵤⽱ֿׅהָדֹךד 㢌侧㹑鎉儗ח⦼然㹀ׇׁ JGFMTFぐـٗحؙך剑䖓ך遤ָ鐰⣣ׁ
+BWB TXJUDI俑 public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) {
case android.R.id.home: finish(); return true; default: return super.onOptionsItemSelected(); } } ⢽ִלًصُ٦鼅䫛儗ךⳢ椚כ+BWBדכTXJUDI俑ד剅ֻֿהָ㢳ְ TXJUDI俑דכ⦼鵤ֿׅהָדֹזְךד؝٦سָ撕꧟חזװְׅ
,PUMJO XIFO䒭 fun onOptionsItemSelected(item: MenuItem?): Boolean = when(item?.itemId) { android.R.id.home
-> { finish() true } else -> super.onOptionsItemSelected() } ,PUMJOחTXJUDI俑כזֻծ➿חXIFO䒭⢪ֲ XIFO䒭כ⽃秪ז瘝⣣嫰鯰⟃㢩ח侧⦼ךٖٝآ䭷㹀װ㘗ثؑحؙ〳腉
㴍׃ְהָֿˑث٦ي˒חוֲ⸬ְגַֻ ِ٦أ؛٦أ邌׃؝٦سחזװְׅ 搀꼽ָזְךד؝٦سٖؽُ٦ָװװְׅ 然钠ה䭷䶯ך怩ָ㼰זֻז 涪ה然钠ךٕ٦ف넝鸞⻉ֿׅהָדֹ
ِ٦ؠ٦פך⣣⦼䲿⣘ח꧊⚥דֹ
孡אְֽהֿ
,PUMJOח蕱ְהָֿ֮ ًاحس侧 ًاحسקו㟓ִ Lًاحسⵖꣲחעאַ〳腉䚍ָ넝ת "OOPUBUJPO1SPDFTTPS
BQQCVJMEHSBEMF BOOPUBUJPO1SPDFTTPS̔LBQUח㢌ִ LBQUָ欰䧭ׅ؝٦سח㉏겗ָֿ֮ה֮
וֲ㼪Ⰵ鹌גְַֻ
$IBU8PSL،فٔך植朐 ،فٔך؝٦سك٦أכ䎃湡ח瑱Ⰵ ⢪גְ⚺זٓ؎ـٓٔ䪮遭 3FUSPMBNCEB 3Y+BWB
-JHIUXFJHIU4USFBN"1* "OOPUBUJPO1SPDFTTPS .VMUJEFY
וַֿ,PUMJO⢪ְ㨣ַ Ⰻגך؝٦س,PUMJOחׅךכ⯓ָ黅ְ 鿇ⴓ涸ח,PUMJO⻉׃גְֻ $IBU8PSLדכאך%JBMPH'SBHNFOUַ הג⽃秪זت؎،ؚٗ
如ח傀㶷ך؝٦سא,PUMJO⻉ ثٍحزٕ٦يך⡲䧭٥刿倜ך"DUJWJUZ ׁחך䖓ծ倜鋉堣腉؝٦س,PUMJOד鷄⸇ 醱꧟זٗآحؙⰅגְ
וֲװגث٦يח嵴鷲ׇׁגְַֻ ,PUMJOأة٦زـحؙ ˑ鸐獥饔ץֿ劤˒Ⰻ㆞飑Ⰵ׃ג䩛⯋ח縧ֻ 爡ⰻך,PUMJOثٍحزד㉔褏崞⹛ +BWBה,PUMJOד剅ְ㜥さך䊴䫎珲
فؙٕٔؒأزח铡僇؝ًٝز♨㻝ח鎸鶢 +BWBדְֲהֿך⡦ַ ,PUMJOך؎ر؍ؔيך铡僇 ٖؽُ٦䖓ثٍحزד椚鍑דַֹ然钠
None
None
ث٦ي㼪Ⰵך铬겗
ث٦يך稆㖑ה׃ג כַׄ+BWBד؝٦س剅ְגְ -BNCEB䒭䫺䫑זֻ「ֽⰅֿהָדֹ -JHIUXFJHIU4USFBN"1*⢪גְ 0QUJPOBMך罋ִ倯ָ㕼〴ח֮ךדծ /VMMBCMFUZQFT
/PO/VMMUZQFT أحה麩ㄤ䠬זֻ《鴥ֿהָדֹ 穠卓ה׃ג ,PUMJOך؝٦سٖؽُ٦כ㉏겗זַ
ד ث٦يⰋ㆞ָ,PUMJOغٔغٔ剅ֽגכְזְ 植㖈䩛ָֽגְ鿇ⴓך麩ְֽ֮ו ⡦וֿתד,PUMJOד剅ַֻכ㹀תגְזְ ꬊず劍Ⳣ椚דBTZODBXBJU⢪גְַֻהַ
Ⰻ㆞ָ駈⚛䲧ִַוֲַ 铩ַ➂ָֽ,PUMJOח枠鹌׃גְֻ朐屣ָ ث٦يחהגծמְגכِ٦ؠ٦ך⣣⦼חזַ ,PUMJOך؝٦س頾⫈ח׃גכְֽזְ
䩛ָֽכׄה׃ג ,PUMJO㼪Ⰵךח+BWBַ㨣ג葺ְַ "OESPJE4UVEJPַכ㢩鿇خ٦ָٕ♶銲חז "OESPJE(SBEMF1MVHJO EFTVHBSخ٦ٕثؑ٦ٝ
-BNCEB䒭װًاحسٔؿ؋ٖٝأָ⢪ִ 傀㶷فٗآؙؑزח,PUMJO㼪Ⰵׅזל 㼭ֻׁ㨣 +BWBך؝٦سָ؎ً٦آדְֹּ㼭ׁזך
ֶ׃תְ