Since Apache Commons is rarely used for Android applications, the StringUtils that we are using in this CodeLab is completely unrelated. Java doesn't have extension functions, so Kotlin compiles these methods as static functions.Įxperienced Java developers might recognize StringUtils as an identifier in the Apache Commons set of libraries. When we converted it to Kotlin, we converted the methods into extension functions. Let's consider the following scenario: we had a StringUtils class with several static functions for string operations. We'll come back to that later.įor now, let's fix the next error in the registerGuest() method. If we switch back to UseCase.java, the properties and methods on Repository are no longer causing errors, except for Repository.BACKUP_PATH. The annotation tells the Kotlin compiler to generate a static version of the annotated member or method. The first function with a problem is registerGuest: public static User registerGuest(String name) Īdd the annotation to your code using your IDE. Let's open UseCase.java and start working through the errors we see. If you're using Android Studio, select "Import project (Gradle, Eclipse ADT, etc.)". If you're using IntelliJ IDEA, select "Import Project". The project's code can be cloned from the GitHub project here: GitHubĪlternatively, you can download and extract the project from a zip archive found here: We'll be fixing all of these in the steps that follow. Since we're simulating refactoring code, the project will contain some errors after it's been imported. We'll imagine we just replaced some functionality originally written in Java with a new version written in Kotlin, and we need to finish integrating it. java file called UseCase.java, which will represent the existing codebase. This codelab simulates migrating part of a larger project written with the Java programming language, to incorporate new Kotlin code. This codelab is written for programmers and assumes basic Java and Kotlin knowledge.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |