Android Studio 3.0 supports the Kotlin language, a new language introduced by Google into the Android ecosystem, with perhaps the intention that it will eventually replace Java, just like Apple created Swift to replace Objective C.

Kotlin is a language designed and developed by a team of JetBrains, the publisher of the renowned development environment Intellij IDEA, on which Android Studio is built. Kotlin borrows from functional programming. It has a static type system (for safety) and supports type inference as well as higher order functions (for lambda expressions and closures). Kotlin also borrows from object programming. While borrowing from functional programming, Kotlin is presented as an object-oriented language. Borrowing from functional programming is mainly to provide coding facilities, according to Kotlin's designers who do not want it to be classified in the category of research or academic languages. On the contrary Kotlin is practical and JetBrains uses it internally in real projects.

No doubt with the intention of stimulating the adoption of Kotlin by developers, Google offers Android KTX. This is a set of extensions designed for writing Kotlin code for Android more concise, idiomatic and enjoyable, says Mountain View. Android KTX brings a nice API overlay to both the Android framework and the Android Support Library, says Google.
For example, installing an event listener in a tree view in Kotlin:

view.viewTreeObserver.addOnPreDrawListener (
    object: ViewTreeObserver.OnPreDrawListener {
        override fun onPreDraw (): Boolean {
            viewTreeObserver.removeOnPreDrawListener (this)
            actionToBeTriggered ()
            return true

With Android KTX, the code becomes:

view.doOnPreDraw {
     actionToBeTriggered ()

Which is undeniably more pleasant.

Leave a Reply