There are two ways to convert your java file to kotlin file.
- Use IntelliJ IDEA
Main menu -> Code -> Convert Java File to Kotlin File
- You can use the online
https://try.kotlinlang.org/ -> Convert from Java
Use IntelliJ IDEA – Convert Java File to Kotlin File
Following are the steps to convert your Java File to kotlin File :
- Open your Project in IntelliJ IDEA, and open the Java file.
- In the main menu bar, click on “Code”. Click on the item “Convert Java File to Kotlin File”
- If you get a message “Some code in the rest of your project may require corrections after performing this conversion. Do you still want to find such code and correct it too?”, you may click OK.
- Finally, your java file is converted to kotlin file. Try running it.
Try Online “Convert from Java”
- Hit the url “https://try.kotlinlang.org/” and click on “Convert from Java”, shown in the below picture
- Paste you Java Code and click on “Convert to Kotlin”
Also learn to convert Java File in Android application to Kotlin File ?