How can I convert a part of Java source file to Kotlin?
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
There is no tool to convert Kotlin code to Java. If you want to convert part of a file from Java to Kotlin, the easiest way is to copy the code from the Java file in the IDE and paste it into the Kotlin file.