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.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
Symfony Mapper Component
soyuka
2
730
CSC509 Lecture 14
javiergs
PRO
0
140
Refactor your code - refactor yourself
xosofox
1
260
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
180
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
250
第5回日本眼科AI学会総会_AIコンテスト_3位解法
neilsaw
0
170
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
210
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
nekko cloudにおけるProxmox VE利用事例
irumaru
3
420
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
1
370
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Docker and Python
trallard
42
3.1k
Facilitating Awesome Meetings
lara
50
6.1k
Being A Developer After 40
akosma
87
590k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Code Reviewing Like a Champion
maltzj
520
39k
The Pragmatic Product Professional
lauravandoore
32
6.3k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
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ך؝٦سָ؎ً٦آדְֹּ㼭ׁזך
ֶ׃תְ