The Update Also Stabilizes Key Language Features, Including a New Approach to Replacing the enum class values Function
Kotlin 1.9.0, the latest release of JetBrains’ popular statically typed language, introduces the beta version of its advanced K2 compiler for the JVM, promising improved performance and a more unified development experience across platforms. This release, rolled out on July 5, 2023, is especially significant for Android developers, where Kotlin has established itself as a primary tool for mobile app development. K2, slated to become the default compiler in Kotlin 2.0, offers a range of enhancements designed to speed up compilation and streamline new feature development.
With Kotlin 1.9.0, basic support for Kotlin/Native and multiplatform projects has been added to K2. The goal of K2 is to provide a cohesive platform that integrates well across all Kotlin-supported platforms, reducing fragmentation and providing a consistent developer experience. Developers can now start experimenting with the K2 compiler by using the Gradle property kotlin.experimental.tryK2=true
. Additionally, Gradle build reports will show whether the current compiler or K2 was used for code compilation, making it easier for developers to monitor and test the performance benefits of the new compiler.
Another exciting improvement is the support for Gradle’s configuration cache in multiplatform libraries. This enhancement further speeds up the build process, which is a critical factor for developers working on large, cross-platform projects. By reducing build times and simplifying dependency management, Kotlin 1.9.0 aims to improve developer productivity.
Alongside the K2 compiler, Kotlin 1.9.0 also stabilizes several key language features introduced in previous versions. Notably, the entries
property for enum classes, which was first introduced as an experimental feature in Kotlin 1.8.20, now replaces the enum class values
function. This new property offers a more streamlined and efficient approach to handling enum class instances, providing developers with a cleaner syntax and improved performance.
Other stabilized features include data object declarations and support for secondary constructors with bodies in inline value classes. Data object declarations, introduced as an experimental feature in Kotlin 1.8.20, provide a way to represent immutable data with improved expressiveness and type safety. These additions help to reduce boilerplate code and enhance Kotlin’s standing as a modern, developer-friendly language.
Kotlin 1.9.0 builds on the momentum of previous releases, such as Kotlin 1.8.0, which added support for Java 19 and experimental directory handling functions for JVM-based projects. Developers eager to explore Kotlin 1.9.0 and its new features can find detailed instructions and resources on the official Kotlin project website.