How to set up Kotlin

How to Set Up Kotlin

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

This article will briefly explain how to setup Kotlin in an existing project. Kotlin is a programming language developed by JetBrains.

Kotlin is a very nice language, heavily based on Scala, it brings a lot of nice functional programming features to java.find functional programming to be particularly efficient when having to deal with the following points:

– Listeners (which is to say always on android): we have lambdas in Kotlin! (Yes yes… you have them with retrolambda, I know!)
– Lots of manipulation of collections (for instance when using adapters): high-order functions will save your life and keep your code clean!
-Using RxJava, RxA ndroid (with the binding RxKotlin): the Reactive Extensions are very useful, yes, but did you try using it with Java ? Unless you’re using retro-lambda, writing all those listeners really is ugly and makes your code unreadable!

To learn more about the cool stuff, I recommend reading the official documentation

Setup

First, you need to add the followign code at the end of your module’s build.gradle file:

You can replace kotlin_version with the latest version or the version you want to use.

Then, you just need to apply the plugin, add the following line at the top of the file:

Kotlin folder

If you want to separate your .java files and your .kt files, you can create a kotlin folder in the same folder as

the java folder. If you do, you need to tell gradle where to get the additional files, to do that add the following lines to your build.gradle:


Leave a Reply