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

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

主站蜘蛛池模板: 沅江市| 驻马店市| 子洲县| 玉环县| 卫辉市| 东城区| 天柱县| 北宁市| 尼玛县| 灌南县| 西充县| 长丰县| 丰顺县| 普兰店市| 湘阴县| 深州市| 嘉黎县| 新绛县| 秭归县| 吐鲁番市| 莲花县| 贺州市| 施甸县| 延长县| 玛多县| 三江| 襄汾县| 和政县| 昌江| 岚皋县| 普安县| 嘉荫县| 南阳市| 休宁县| 融水| 奉节县| 定西市| 宜川县| 张家界市| 鹤山市| 遂昌县|