Kotlin 1.5 - Mature But Still Growing
Written by Mike James   
Tuesday, 18 May 2021

A 1.5 release is always interesting and Kotlin continues its development into a "do-it-all" language with its latest update.

The first thing to say is that Kotlin is a very mature language and there isn't going to be much scope for radical changes. This said, it has to keep an eye on developments in Java  in order to remain compatible. Hence it has now graduated from experimental to stable its support for JVM records. Kotlin has had its own data class for ages and now Java has caught up. The only real difference between the two is that JVM records don't have a copy method, but data classes do. All you have to do to ensure compatibility with JVM records is use a @JvmRecord annotation.


The other improvements are equally minor. Subclasses of sealed classes can now be spread through a compilation unit whereas previously they all had to be in the same file.

An interesting introduction is the idea of an inline class - although the terminology is a bit outdated. There is nothing much inline about an inline class and they would better be called "value classes". Primitive data types like Int are value classes. Primitive value are often used "raw", i.e. without any pretense that they are objects, but to maintain the idea that they are objects they can be "boxed" so as to look like an object. One key difference is that such value objects generally don't maintain their identity unless they are boxed. That is, one 3 is the same as any other 3 - unless the value is boxed when each boxed value object is different, even if they happen to represent the value 3.

This is the sort of subtle stuff that can drive you mad and now you can go mad more effectively with the introduction of custom value classes. At the moment value classes are limited to a single field so you can't create a complex number value class. For example:

inline class Color(val rgb: Int)

defines a class that is essentially the same as an Int and indeed is substituted for by an Int where ever possible i.e. no wrapper, no boxing. This sort of thing is of limited use but it does allow you to create custom scalar and String types.

The biggest improvements aren't really in the language, but in its implementation and support. The new IR (Intermediate Representation) backend provides a unified compiler for the three main branches of Kotlin implementation - JVM, JS and Native. This means that any fixes or improvements are applied to all three implementations making using any one of them a better proposition.

Kotlin 1.5 is a good step to have made during Kotlin's tenth year of being a better Java. It is such a better Java that there isn't much room left for making it a better Kotlin. But this is no problem and it's a really great language that is both fun and efficient.




More Information

Kotlin 1.5.0 – the First Big Release of 2021

Related Articles

Kotlin 1.4 Improves Node.JS Support

Kotlin - another Java alternative? 

Why Do Android Devs Convert To Kotlin?

Kotlin Versus Java - A Developer's Rosetta Stone

Kotlin 1.3 Adds Duration And Time API

Kotlin Enters RedMonk's Top 20

Kotlin Gains A Foundation and A Portal

Kotlin 1.2 Released With Cross Platform Support

Kotlin Goes Open Source

Can a Language Make You a Better Programmer? Kotlin & Android

Kotlin - New Language For Android

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.



GR00T Could Be The Robot You Have Always Wanted

We may not have flying cars, but we could well soon have robots that match up to predictions for the 21st century. Nvidia has announced GR00T, a cleverly named project to build robots using foundation [ ... ]

Java Version 22 Released

JDK 22 is not a Long Term Support release, but is one of the regular releases that are scheduled to arrive every six months. Still, it has got a lot to show for itself.

More News

raspberry pi books



or email your comment to: comments@i-programmer.info



Last Updated ( Friday, 19 August 2022 )