

The second half is a discussion of some of the disadvantages of using Kotlin instead of Java.Īrguably the best feature of Kotlin is its null-safety. The first half of this post is a discussion of some of the key features of Kotlin that make it stand out. As you can see, IntelliJ IDEA has great support for Kotlin, which is extremely beneficial given that Android Studio is built on top of the IDE, thus making Kotlin a first-class citizen in the world of Android development.Īs you are reading this blog post I would recommend trying out the examples here, and you will see first hand the advantages and disadvantages of the language. Due to the similarities with Java, the language is easy (and thus cheap) to learn, especially given Intellij IDEA’s automatic Java to Kotlin converter which runs automatically when you copy-paste Java code into the editor. As a result of this, Kotlin is interoperable with Java when written for the JVM or Android, and - with a little difficulty - JavaScript too. Kotlin was initially designed to join the ranks of the JVM languages but has quickly expanded to other platforms in 2017 version 1.2 was released which enabled developers to transpile Kotlin code to JavaScript. In Kotlin, the type system distinguishes between references that can hold null (nullable references) and those that cannot (non-null references).Released in February 2016, Kotlin is an open source language initially developed by JetBrains and named after Kotlin Island which is off the west coast of St Petersburg in Russia. Other issues caused by external Java code. For example, a piece of Java code might add null into a Kotlin MutableList, therefore requiring a MutableList for working with it.

Nullability issues with generic types being used for Java interoperation. Usage of the !! operator that is described below.ĭata inconsistency with regard to initialization, such as when:Īn uninitialized this available in a constructor is passed and used somewhere (a "leaking this").Ī superclass constructor calls an open member whose implementation in the derived class uses an uninitialized state.Īttempts to access a member of a null reference of a platform type The only possible causes of an NPE in Kotlin are:Īn explicit call to throw NullPointerException(). In Java this would be the equivalent of a NullPointerException, or an NPE for short. One of the most common pitfalls in many programming languages, including Java, is that accessing a member of a null reference will result in a null reference exception. Kotlin's type system is aimed at eliminating the danger of null references, also known as The Billion Dollar Mistake. Null safety Nullable types and non-null types
