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
Convert Java File to Kotlin File おかしな変換集
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Takehata Naoto
August 25, 2018
Programming
790
1
Share
Convert Java File to Kotlin File おかしな変換集
Kotlin Fest 2018のLT大会発表のスライドです。
Takehata Naoto
August 25, 2018
More Decks by Takehata Naoto
See All by Takehata Naoto
AI時代でも変わらない技術コミュニティの力~10年続く“ゆるい”つながりが生み出す価値
n_takehata
2
1.1k
KotlinConf 2025で発表された言語のアップデートと現地参加レポート
n_takehata
2
380
KotlinConf 2025 現地で感じたServer-Side Kotlin
n_takehata
2
480
KotlinConf 2025 現地参加の土産話
n_takehata
0
210
組織貢献をするフリーランスエンジニアという生き方
n_takehata
1
6.3k
「2024年版 Kotlin サーバーサイドプログラミング実践開発」の補講 〜O/Rマッパー編〜
n_takehata
2
820
2024年版 Kotlin サーバーサイドプログラミング実践開発
n_takehata
9
8.9k
Server-Side目線で見る、Kotlin Festの楽しみ方
n_takehata
0
620
KotlinとCloud Vision APIで領収書の電子帳簿保存法対応をする
n_takehata
1
2k
Other Decks in Programming
See All in Programming
Inspired By RubyKaigi (EN)
atzzcokek
0
430
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.8k
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
130
inferと仲良くなる10分間
ryokatsuse
1
270
TypeSpec で繋ぐ複数プロダクトの型安全
maroon8021
1
260
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
310
Zod v4 Codec でスキーマに型変換を埋め込む REST API 設計 #TSKaigi2026
ryutaro_yako
0
170
iOS26時代の新規アプリ開発
yuukiw00w
0
220
TSKaigi 2026 TypeScriptバックエンドのオブザーバビリティ戦略 — Datadog × NestJSの実践
taiseiyamamotoan
1
210
Swiftのレキシカルスコープ管理
kntkymt
0
200
Migrations : C'est une question d'hygiène !
vinceamstoutz
0
2.5k
分析エージェント精度向上における データアナリストの役割
oura_shoya
0
140
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
22k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.9k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
270
Building an army of robots
kneath
306
46k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.5k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
Ethics towards AI in product and experience design
skipperchong
2
290
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
170
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
270
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
160
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
150
Transcript
Convert Java File to Kotlin File おかしな変換集 株式会社 アプリボット ⽵端
尚⼈
⾃⼰紹介 ⽵端 尚⼈ @n_takehata 分野:サーバーサイドエンジニア(Kotlin) 2006.04 2007.12 2011.01 2014.04 公務員
SES サイバーエージェント アプリボット 業種:ゲーム開発
省略します
• IntelliJにはJavaのコードをKotlinに変換して くれる素晴らしい機能があります • 対象ファイルを選択 -> Code -> Convert Java
File to Kotlin File
2万⾏を⼀気に変換した時に出た おかしな変換例を紹介します!
1個⽬
public String getMessage() { UserService userService = new UserService(); return
userService.createMessage(); } val message: String get() { val userService = UserService() return userService.createMessage() } なんかプロパティになってる Java Kotlin
拡張プロパティ val score1 = 0 val score2 = 0 val
totalScore get() = score1 + score2 ・get〜という名前の引数なしメソッドが 全てプロパティとして認識されてしまう ・割とゴリゴリ処理を書いた拡張プロパティが できあがった
2個⽬
Java Kotlin public sta8c Integer calc(Integer num1, Integer num2) {
return num1 + num2; } companion object { fun calc(num1: Int?, num2: Int?): Int { return num1!! + num2!! } } 謎のオブジェクトcompanionが出現する
コンパニオンオブジェクト Javaから呼び出そうとすると、Companionというオブジェクトを 経由しなくてはならなくなる companion object { fun execute() { //
・・・ } } Sample.Companion.execute(); Java Kotlin staticな関数を定義したい時、コンパニオンオブジェクトを使う
companion object { @JvmStaMc fun execute() { // ・・・ }
} @JvmSatic付けてあげてね
3個⽬(最後)
Java public String execute(Integer userId, Integer targetId) { Map<Integer, String>
userMap = createUserMap(); return userMap.entrySet() .stream() .filter(entry -> { if (userMap.containsKey(userId)) { return true; } if (userMap.containsKey(targetId)) { return true; } return false; }).map(entry -> { return entry.getValue(); }).toString(); }
Kotlin fun execute(userId: Int?, targetId: Int?): String { val userMap
= createUserMap() return userMap.entries .stream() .filter { entry -> if (userMap.containsKey(userId)) {
[email protected]
() .stream() .filter true } if (userMap.containsKey(targetId)) {
[email protected]
() .stream() .filter true } false }.map { entry -> entry.value }.toString() }
難しいのであとで聞いてください
• Convert Java File to Kotlin Fileは素晴らしい 機能 • でも頼りすぎるとエラーまみれになる
ツールの⽤法・容量を守って Kotlinを愛でましょう
Kotlinかわいい!
以上