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

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

主站蜘蛛池模板: 新化县| 家居| 枣阳市| 资中县| 于田县| 微山县| 武陟县| 营口市| 郧西县| 昌都县| 郓城县| 高淳县| 永宁县| 仲巴县| 增城市| 宿松县| 临猗县| 米林县| 临潭县| 临沂市| 长子县| 依安县| 天祝| 贺州市| 云和县| 岑巩县| 凌源市| 冷水江市| 台中市| 金寨县| 巴南区| 陕西省| 滦平县| 三门峡市| 化隆| 丰县| 泰安市| 新闻| 莲花县| 莱芜市| 虎林市|