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

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).

主站蜘蛛池模板: 卓尼县| 融水| 巢湖市| 松阳县| 常州市| 石嘴山市| 富源县| 仁布县| 青田县| 申扎县| 平顶山市| 保山市| 钟祥市| 桐庐县| 清原| 上虞市| 咸阳市| 柘城县| 三都| 宝应县| 修武县| 太和县| 绩溪县| 施秉县| 临西县| 岐山县| 汨罗市| 抚远县| 汶川县| 肇州县| 苏州市| 沙湾县| 宁蒗| 壤塘县| 商丘市| 南陵县| 大丰市| 阳东县| 新郑市| 友谊县| 敦煌市|