Convert Java file to Kotlin in Intellij Idea

Introduction :

You can use both Kotlin and Java files in a Kotlin program. Like if you want to move your Android project from Java to Kotlin, you can do that. You can add new files as kotlin files. Or, you can convert your existing Java files as well.

There are different online tools to convert Java to kotlin, but I alawys find the inbuilt converter provided by Intellij-IDEA. Kotlin is a JetBrain product, so we can always have the updated converter with Intellij-IDEA. In this post, I will show you how to convert Java to Kotlin using Intellij-IDEA.

Java to Kotlin in Intellij-IDEA :

This tutorial is for Intellij-IDEA IDE. If you don’t have it, you can download from here.

Step-1: Open the project on Intellij-IDEA. Right-click on the Java file and click on Convert Java File to Kotlin File to convert it to Kotlin.

java to kotlin in intellij idea

Step-2: It will show you a popup that some code in the project may require correction and do you want to find and correct such code. Click yes. That’s it. It will convert the Java file to a Kotlin file.

java to kotlin intellij idea

Undo conversion: To undo a change, click ctrl+z or Cmd+z, it will ask with a popup, click OK and you will get back your original Java file.

undo java to kotlin intellij idea

Another way to convert: Conversion option is also available in the code menu. Or you can use the shortcut. The shortcut is different on different OS. It is shown near that conversion option.

java to kotlin intellij idea

Similar tutorials :

Where is the color and why codevscolor ?

Long story short, I love paintings and I paint on weekends. We(me and my wife) have one Youtube channel. Below is a video that I did recently. If you love this please do subscribe to support us 😊