BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News The Road to Kotlin 1.5

The Road to Kotlin 1.5

This item in japanese

Lire ce contenu en français

Bookmarks

JetBrains has released Kotlin 1.4.30 with new experimental features that are planned to be stable for Kotlin 1.5, currently in milestone release and scheduled for GA release mid-2021. Considered the last incremental version of Kotlin 1.4.x, these new features include: a new JVM internal representation (IR) compiler backend, support for Java records and sealed interfaces, and configuration cache support for the Kotlin Gradle Plugin. JetBrains is encouraging the Kotlin community to test these new features, especially the new JVM IR backend, in their applications using Kotlin 1.4.30 and report any bugs using their YouTrack issue tracker.

Complementing the compiler frontend, responsible for analyzing the source code, the new JVM IR backend, currently in beta, will be the default compiler in Kotlin 1.5. It is composed of three separate backends: Kotlin/JVM, Kotlin/JS and Kotlin/Native. The first two, having been developed independently, will be integrated into the new JVM IR infrastructure within Kotlin/Native.

Changes with the new backend include: a number of bug fixes that were present in the old backend and the development of new language features to improve performance. Android's new toolkit for building UIs, Jetpack Compose, will only work with the new backend.

Alina Grebenkina, marketing lead at JetBrains, discussing the advantages of consolidating the three backends, writes:

We will share a lot of the backend logic and have a unified pipeline to allow most of the features, optimizations, and bug fixes to be done only once for all targets.

Having a common backend infrastructure opens the door for more multi-platform compiler extensions. It makes it possible to plug into the pipeline and add some custom processing and/or transformations that will automatically work across all targets.

With the release of Java 16, Kotlin has provided support for the new record data type to maintain interoperability between Kotlin and Java. A Java record data type may be declared in Kotlin using the new @JvmRecord annotation:

    
@JvmRecord
data class User(val name: String, val age: Int)
    

Compiler options -Xjvm-enable-preview and -language-version 1.5 must be used to experiment with this new feature.

Sealed interfaces were designed to complement sealed classes to create a more flexible sealed class hierarchy. It is also possible for a derived class to inherit from more than one sealed interface:

    
sealed interface Fillable {
    fun fill()
    }

sealed interface Polygon {
    val vertices: List<Point>
    }

class Rectangle(override val vertices: List<Point>): Fillable, Polygon {
    override fun fill() {
        /*...*/
        }
    }
    

To improve the build performance, the Kotlin Gradle plugin is now compatible with the Gradle configuration cache, an incubating Gradle feature that improves build times by caching the result of the configuration phase and reusing it for subsequent builds. Consider the following example:

    
$ gradle --configuration-cache help
Calculating task graph as no configuration cache is available for tasks: help
...
BUILD SUCCESSFUL in 4s
1 actionable task: 1 executed
Configuration cache entry stored.
    

Executing the same command again will produce:

    
$ gradle --configuration-cache help
Reusing configuration cache.
...
BUILD SUCCESSFUL in 500ms
1 actionable task: 1 executed
Configuration cache entry reused.
    

Notice the difference in build times. The plugin works with Gradle 5.4+ and more details on how to use the configuration cache may be found in the Gradle documentation.

Last fall, JetBrains announced they will be following a new release cadence to provide an updated version of Kotlin every six months.

Further details about this latest release may be found in the what's new section of the Kotlin documentation.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT