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.

kotlinlogo

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.

kotlinlogo

 

 

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.

 

Banner


Kafka 3.9 Adds Dynamic KRaft Quorums
16/12/2024

Kafka 3.9 has been released. The team says this is a major release and the final in the 3.x line. It This will also be the final major release to feature the deprecated Apache ZooKeeper mode. Kafka is [ ... ]



Pico 2W Announced But There Is A Surprise!
25/11/2024

Raspberry Pi released the Pico 2 a few months ago and we have been waiting for the Pico 2W since then. But Pimoroni beat them to the draw with the Pico Plus 2W based on the RM2 radio module and hinted [ ... ]


More News

espbook

 

Comments




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

<ASIN:1871962706>

<ASIN:1871962544>

Last Updated ( Friday, 19 August 2022 )