Google launches Kotlin migration guide for Android developers’ preferred language

On Google I/O in May, Google announced that Kotlin-first, Kotlin became the language of choice for Android developers, and google continued its build-up to Kotlin. This article provides an overview of Google’s Kotlin migration guide.

Start migrating from Java to Kotlin

Google recommends “points and sides” migration, including people and code:

At the human level, the team has chosen a Kotlin “promotion altogether” who needs to do:

Learn about Kotlin and become an expert

Develop the Kotlin development process

Participate in code reviews to ensure the Kotlin development process is successfully implemented

Build an in-company/team learning group

Proactively collect internal issues and discuss them with feedback from the developer community

At the code level, you need to:

Write tests first using Kotlin (the project is still using Java)

Write new code with Kotlin

Update the existing code to Kotlin code

When updating your existing code to Kotlin code, you can use the Java-to Kotlin tool provided by Android Studio, just select “Code and Convert Java File to Kotlin File” in the menu:

谷歌推出 Kotlin 迁移指南 Android开发者的首选语言

Java-to-Kotlin tool

In addition, Kotlin’s migration efforts don’t have to be done overnight, and developers can move on their own pace. A project can contain both a .java and a .kt file, but you can’t have both Java and Kotlin in the same file, and developers can use any Java library in Kotlin code.

谷歌推出 Kotlin 迁移指南 Android开发者的首选语言

Kotlin interoperability check can also be turned on in the Lint check for Android Studio

There are a few things to note when calling Java in Kotlin:

Mark code as @Nullable and @NotNull

Use the property prefix (getName),), setName (), isActive())

Avoid using reserved keywords in Kotlin (when, is, etc.)

A more detailed Kotlin interoperability guide can be found on the Android developer website:

Add a Comment

Your email address will not be published. Required fields are marked *