Life is good and everything will be ok, Kotlin is here…
In this article we will check how we can start with Kotlin for Android.
Make sure you won’t overwrite your old Android Studio when you install the new version.
Method 1 :
Pre-requisites
First you have to download Android Studio Beta 3.0 from here.
Android Studio has support for Kotlin. Go to Create Android Project. You will see new thing there: Checkbox with label include Kotlin support. It is checked by default. Press next twice and select Empty Activity, then finish.
package com.coderzheaven.kotlin_demo import android.support.v7.app.AppCompatActivity import android.os.Bundle class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } }
.kt is the extension for Kotlin Files.
? in savedInstanceState: Bundle? ? It means that savedInstanceState parameter can be Bundle type or null. Kotlin is null safety language that means in Kotlin, you will never see the famous Null Pointer Exception.
Method 2 :
You can install Kotlin Plugin for Android Studio.
Go to Preferences -> Plugins -> Search for Kotlin and install.
Then Restart the Android Studio and there you are.
You are now ready with Kotlin.