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
410
チーム開発と Android アプリの構成
ryugoo
5
1.2k
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
Rubyでつくるパケットキャプチャツール
ydah
0
170
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
6
1.4k
快速入門可觀測性
blueswen
0
500
知られざるDMMデータエンジニアの生態 〜かつてツチノコと呼ばれし者〜
takaha4k
1
450
chibiccをCILに移植した結果 (NGK2025S版)
kekyo
PRO
0
130
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
770
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
3
190
ESLintプラグインを使用してCDKのセオリーを適用する
yamanashi_ren01
2
240
Запуск 1С:УХ в крупном энтерпрайзе: мечта и реальность ПМа
lamodatech
0
950
歴史と現在から考えるスケーラブルなソフトウェア開発のプラクティス
i10416
0
300
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
300
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
4
1.1k
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
Rails Girls Zürich Keynote
gr2m
94
13k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
Facilitating Awesome Meetings
lara
51
6.2k
The Cult of Friendly URLs
andyhume
78
6.1k
Designing for humans not robots
tammielis
250
25k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
960
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
19
2.3k
Into the Great Unknown - MozCon
thekraken
34
1.6k
Practical Orchestrator
shlominoach
186
10k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
230
52k
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ך؝٦سָ؎ً٦آדְֹּ㼭ׁזך
ֶ׃תְ