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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Takehata Naoto
August 25, 2018
Programming
1
770
Convert Java File to Kotlin File おかしな変換集
Kotlin Fest 2018のLT大会発表のスライドです。
Takehata Naoto
August 25, 2018
Tweet
Share
More Decks by Takehata Naoto
See All by Takehata Naoto
AI時代でも変わらない技術コミュニティの力~10年続く“ゆるい”つながりが生み出す価値
n_takehata
2
750
KotlinConf 2025で発表された言語のアップデートと現地参加レポート
n_takehata
2
360
KotlinConf 2025 現地で感じたServer-Side Kotlin
n_takehata
2
430
KotlinConf 2025 現地参加の土産話
n_takehata
0
190
組織貢献をするフリーランスエンジニアという生き方
n_takehata
1
5.9k
「2024年版 Kotlin サーバーサイドプログラミング実践開発」の補講 〜O/Rマッパー編〜
n_takehata
2
790
2024年版 Kotlin サーバーサイドプログラミング実践開発
n_takehata
9
8.6k
Server-Side目線で見る、Kotlin Festの楽しみ方
n_takehata
0
590
KotlinとCloud Vision APIで領収書の電子帳簿保存法対応をする
n_takehata
1
1.9k
Other Decks in Programming
See All in Programming
Codex の「自走力」を高める
yorifuji
0
1.2k
ふつうの Rubyist、ちいさなデバイス、大きな一年
bash0c7
0
940
OTP を自動で入力する裏技
megabitsenmzq
0
100
モダンOBSプラグイン開発
umireon
0
120
Agent Skills Workshop - AIへの頼み方を仕組み化する
gotalab555
15
8.7k
Claude Code Skill入門
mayahoney
0
380
go directiveを最新にしすぎないで欲しい話──あるいは、Go 1.26からgo mod initで作られるgo directiveの値が変わる話 / Go 1.26 リリースパーティ
arthur1
2
550
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
280
20260315 AWSなんもわからん🥲
chiilog
2
150
RAGでハマりがちな"Excelの罠"を、データの構造化で突破する
harumiweb
9
2.8k
技術検証結果の整理と解析をAIに任せよう!
keisukeikeda
0
120
米国のサイバーセキュリティタイムラインと見る Goの暗号パッケージの進化
tomtwinkle
2
580
Featured
See All Featured
Everyday Curiosity
cassininazir
0
160
Utilizing Notion as your number one productivity tool
mfonobong
4
260
[SF Ruby Conf 2025] Rails X
palkan
2
830
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
72
Speed Design
sergeychernyshev
33
1.6k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
110
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
160
Building Adaptive Systems
keathley
44
3k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8k
The Cost Of JavaScript in 2023
addyosmani
55
9.8k
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かわいい!
以上