![]() ![]() While this scratches the surface, there's much more to learn. In summary, this targeted quick mini course cleverly teaches the basics of Kotlin by leveraging the existing knowledge in Java but shifting the paradigm to Kotlin - it's much easier to learn by observing how the old constructs map to their newest counterparts than starting from scratch. The rest of the tutorial enriched the code with more improvements such as marking the User class as a "data" Kotlin class, using default and named arguments, using string templates, ending up with a run down on the let, apply, etc functions. The converter while doing its job properly, still needs a bit of help to become more efficient.įor example, User class has two properties: firstName and lastName which can be null, something that the converter did not pick up.So there's two options here, either annotate your Java class properties with or and re-run the conversion or directly modify the Kotlin code by suffixing "String" with a "?" which Kotlin uses to denote nullability. It requires firing up Android Studio or IntelliJ IDEA, copy the two sample classes and run the converter to turn them from. The lab begins where the automatic conversion of two simple Java classes, User and Repository, to their Kotlin counterparts ends, cherry picking the converted code to not just improve it but also teach Kotlin in the process. The Refactoring to Kotlin Codelab aims to change that. Moreover, given you are naturally predisposed to continue writing Kotlin as if it was Java, following Java's practices and idioms, this won't make the most of Kotlin's fresh approach. ![]() ![]() While the latest IDE's do a good job in automatically converting Java code into Kotlin, this doesn't necessarily help you understand the mapping from the one code base to the other. Refactoring to Kotlin, which is available in English, Brazilian and Chinese, provides a guided, hands-on coding experience in a running time of just less than an hour. Learn how to convert Java to Kotlin using Kotlin's idioms with Google Developers Codelabs. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |