Thursday, November 15, 2018

How to convert java code into kotlin in android

Kotlin is a language which is supported by Google as a official language for android development.So,
Android Studio 3.0 is now fully supported Kotlin (no need for extra plugin). If you are using Android Studio >= 3.0 then below jobs are very easy :-

1. Converting Existing Java Code into Kotlin :-
Android Studio Menu -> Code -> Convert Java File to Kotlin File
                                                        Or
Create a new Kotlin file and paste your java code in that file- when Android studio prompted for converting java code into kotlin click Yes.

2. Create a new Kotlin file :-
File -> New-> Kotlin File

3. Convert a part of Java code into Kotlin :-
 Copy you java code snippet from Java file and paste into Kotlin file- when Android studio prompted for converting java code into Kotlin click Yes.


Note :- 
1.When you are creating your project in Android studio you have to click include Kotlin support.
2. For older version of Android studio you need to add Kotlin plugin.

1 comment: