官术网_书友最值得收藏!

Java to Kotlin converter (J2K)

Migration of existing Java projects is also quite easy, because we can use Java and Kotlin side by side in the same project. There are also ways to convert existing Java code into Kotlin code by using the Java to Kotlin converter (J2K).

The first way is to convert whole Java files into Kotlin files using the convert Java File to Kotlin command (the keyboard shortcut in Windows is Alt + Shift + Ctrl + K and in macOS is option + shift + command + K), and this works very well. The second way is to paste Java code into an existing Kotlin file and the code will also be converted (a dialog window will appear with a conversion proposition). This may be very helpful when learning Kotlin.

If we don't know how to write a particular piece of code in Kotlin, we can write it in Java, then simply copy to the clipboard and paste it into the Kotlin file. Converted code will not be the most idiomatic version of Kotlin, but it will work. The IDE will display various intentions to convert the code even more and improve its quality. Before conversion, we need to make sure that the Java code is valid, because conversion tools are very sensitive and the process will fail even if a single semicolon is missing. The J2K converter combined with Java interoperability allows Kotlin be introduced gradually into the existing project (for example, to convert a single class at a time).

主站蜘蛛池模板: 土默特右旗| 玉田县| 勐海县| 浮山县| 富宁县| 大新县| 浦东新区| 新宾| 通海县| 临朐县| 平山县| 仪陇县| 永嘉县| 孝感市| 格尔木市| 宜都市| 乐至县| 宜君县| 弋阳县| 怀化市| 中宁县| 景谷| 青浦区| 明水县| 原阳县| 佛教| 顺昌县| 建瓯市| 泾阳县| 遵化市| 丰台区| 阿克苏市| 花莲县| 麻阳| 德保县| 金湖县| 阳高县| 行唐县| 大姚县| 鱼台县| 慈溪市|