Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
119 views
in Technique[技术] by (71.8m points)

android - How can I convert a part of Java source file to Kotlin?

In my Kotlin project, I have some parts of Java code that I want to convert to Kotlin. The menu item that converts the Java file to Kotlin is disabled because it's not a whole file I want to convert.

How can I convert Java code to Kotlin?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

With Android Studio 3.0

You don't need to install any plugin to convert java code to kotlin code. Now, Google is officially supporting Kotlin language.

  • Android Studio Menu -> Code -> Convert Java File to Kotlin File

Before Android Studio 3.0

If you are using older Android Studio ( which is below version 3.0 ) there is a Kotlin tool under the menu.

Installing Kotlin plugin :

  • Android Studio Menu -> File -> Settings -> Plugins -> Browse repositories -> Kotlin

Converting Java Code to Kotlin Code :

  • Select your java class file from project structure.
  • Android Studio Menu -> Code -> Convert Java File to Kotlin File

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...