You look so good. You’re here. Follow me. Learn more about the latest knowledge and learn a little bit every day

preface

Since Google announced support for Kotlin in 2017, we’ve received a lot of questions about Kotlin on Android. Such as:

  1. When should I learn it from development
  2. What is the best course or documentation for studying Kotlin
  3. Whether Kotlin has been used internally at Google
  4. What are Google’s plans for the Java language?

In this article, I answer those questions.

Question 1: Should I learn to use Kotlin on Android?

Related questions include:

  1. As a beginner, how should I choose between Kotlin and Java
  2. As a developer who has mastered the basics of Java, it’s time to learn whether Kotlin’s Android development is the right thing to do.
  3. As an experienced Java developer, if I am engaged in Android development, do you recommend me to use Java or Kotlin development

Short answer:

You should start learning and using Kotlin right away

Long answer:

Since we started recommending Kotlin in 2017, our first step was to make sure our apis, documentation, and examples were kotlin-friendly. We have also come to rely on some of the Kotlin features. For example, coroutines are a recommended way to solve asynchronous work. Here are some additional things we do:

The library will support Kotlin first

In the Android Jetpack API, we support Kotlin’s coroutines in preference. Such as Room, LiveData, ViewModel and WorkManager.

For example, the Firebase Android SDK and many Jetpack libraries use Kotlin extensions (KTX) to make coding smoother.

Currently, many libraries such as Paging 3.0 and DataStore are developed using Kotlin in preference. In particular, Jetpack Compose, a new UI toolkit, is based on Kotlin

tool

Development productivity comes from great tools, such as: we made many optimizations to the Kotlin compilation toolchain, including enhancing the Kotlin JVM compiler, R8 optimizations for Kotlin, and even a new annotation/symbol driver.

We’ve added a built-in Android Kotlin template (Live Templates), which allows you to quickly add fixed-structure code. At the same time, the new Kotlin Lint checking tool will make your code more Kotlin compliant. This is very useful, especially in the transition from Java to Kotlin.

Question 2: Does Google use Kotlin internally

Inside Google, we double down on Kotlin, with over 60 of our apps (e.g., Google Home, Drive, Maps…). Kotlin has been added to the project.

Our internal code repository, over two million lines of code are Kotlin

Question 3: Do I need to migrate my App to Kotlin

We get this question all the time, but the answer is really up to you. If you like your current technology stack and are adept at using existing solutions to solve complex scenarios. Such as asynchronous tasks. And there are efficient ways to find and resolve errors. Then maybe migration is not a good fit.

If you like to try out some new features with Kotlin, you also like to use Jetpack’s latest support for Kotlin. Then you should consider adding Kotlin to your project.

After all, Kotlin and existing Java code can coexist and interact perfectly. You can use it bit by bit on a small scale, and then try to convert some of the old code to Kotlin for new features.

If you haven’t already added Kotlin to your project, you can refer to this resource: Converting to Kotlin Codelab

Question 4: What is the Java language plan for Android?

Currently Java and Kotlin compile the same bytecode and coexist. Although we like the expressiveness and security of Kotlin’s coding. But we will continue to maintain and evolve Java. For example, in Android 11, we added a number of OpenJDK apis that you can use on all devices.

Question 5: What is the best way to learn Kotlin

Adopting a new language isn’t always easy, but we try to make it as easy as possible.

  1. Through training courses, it is aimed at developers of all levels. Will improve your skills in Android development. Android Basics in Kotlin is another online course for those with no development experience. From the basics to teaching you how to use coroutines
  2. All of our documentation pages support Kotlin fragments. So you can easily compare how the code works. All samples currently have Kotlin’s version.
  3. Check out our articles and videos to teach you a lot about Kotlin
  4. Learn how to switch to Kotlin in the Kotlin article on the official website

Final conclusion

Kotlin has been officially supported since 2017, and we’ve been working with JetBrains to support this great language and system. We will make sure that Kotlin’s development is steady. The libraries we released not only support Kotlin, but are Kotlin-first. We are very determined to make Kotlin’s development on Android enjoyable!

Follow the wechat official account to learn more tips. Make a little progress every day