Kotlin is a renowned name in the development industry. It is a programming language developed by Jet Brains and introduced in 2011 that continues to gain traction in the development world, from developing Android to server-side applications. To keep up with the growing evolution in the development industry, Kotlin programming language continues to release the update to help you develop highly scalable applications.
This time Kotlin is here with the latest release: Kotlin 1.9.0. They gave the update earlier this month on 6th July 2023.
Since its inception, kotlin development services always stand up to expectations. From resolving compatibility issues to multiple support available, this release brings lots to the rescue.
Continue reading the blog to discover what’s new with the update and some key highlights of 1.9.0.
The latest update in the Kotlin 1.9.0 release
Here are highlights of Kotlin 1.9.0’s exciting new features and improvements.
Inline Classes
As of Kotlin 1.9.0, the language now supports inline classes, a lightweight wrapper class that disappears at runtime. Using inline classes makes your code more efficient owing to the ease with which you can create new types. It is possible to encapsulate a specific type within an inline class utilizing the inline keyword, thus ensuring type safety without compromising performance.
New Kotlin K2 Compiler Updates
A new version of JetBrains’ Kotlin compiler, 1.9.0, introduces further improvements to the K2 compiler. There is now a Beta version of the K2 JVM compiler.
Multiplatform and Kotlin/Native projects are now also supported.
K2 and Kapt Compiler Plugin Compatibility
Using the Kapt plugin in conjunction with the K2 compiler is possible, but certain restrictions apply. The Kapt compiler plugin uses the old compiler even though the language version is 2.0.
Kapt will automatically switch to 1.9 if the language version is 2.0 and disable compatibility checks for specific versions. As a result, you’ll need to include these command arguments:
-Xskip-metadata-version-check -Xskip-prerelease-check -Xallow-unstable-dependencies
Checks like these aren’t enabled for kapt tasks. The K2 compiler will be used for all other compilation tasks.
Report any issues you run into when using kapt with the K2 compiler.
Try Out the K2 Compiler
The Kotlin.experimental.tryK2=true Gradle property lets you test the K2 compiler starting with 1.9.0. Here’s what you need to do:
./gradlew assemble -Pkotlin.experimental.tryK2=true
Using this Gradle property, K2 compiler tasks are compiled automatically with the 2.0 language version:
##### 'kotlin.experimental.tryK2' results (Kotlin/Native not checked) ##### :lib:compileKotlin: 2.0 language version :app:compileKotlin: 2.0 language version ##### 100% (2/2) tasks have been compiled with Kotlin 2.0 #####
Gradle build reports: Code build reports show whether K2 or current compilers were used to compile the code.
Kotlin/Native
The Kotlin/Native memory manager has been further improved in this release with the some worth noticing improvements.
Multiplatform Support for Kotlin
Several features have been added to Kotlin Multiplatform in 1.9.0 to enhance the developer experience:
Changes in Android Target Support
Supporting Android first-class is an essential step. Android will be supported by a Gradle plugin provided by the Android team at Google.
1.9.0 renames the android block in the Kotlin DSL to androidTarget for this new Google solution. The android block in your build scripts needs to be changed to androidTarget. For the upcoming DSL, the Android name must be freed up from Google for a temporary period.
Source set layout for Android is now enabled by default
It is the default layout for Android source sets as of Kotlin 1.9.0. Several confusing directories were replaced with the new naming schema.
Configuration cache preview for Gradle
Gradle configuration cache is now supported by Kotlin 1.9.0 in multiplatform libraries. There has already been an improvement in performance in the build process for library authors, so you can already benefit from this one.
Reusing configuration results during subsequent builds speed up the Gradle build process. Stable has been added to the feature since Gradle 8.1. Follow the Gradle documentation for instructions on how to enable it.
Improvements to concurrency
With Kotlin 1.9.0, concurrent programming tasks are handled substantially better. Several new coroutine constructs have been added to the standard library, making it easier for users to write asynchronous code. Introducing structured concurrency ensures proper management of coroutines, reducing instances of resource leaks and unintentional cancellations.
Kotlin/Wasm
With Kotlin/Wasm, the Kotlin team is continuing to experiment. Several optimizations related to performance and size have been implemented in this release, along with updates in JavaScript interoperability.
- A size-related optimization: The WebAssembly (Wasm) project size has been significantly improved in Kotlin 1.9.0. Compared to Kotlin 1.8.20, the Wasm project footprint in 1.9.0 is over ten times smaller. With these size optimizations, Kotlin code targeting Wasm platforms uses resources more efficiently and performs better.
- Interoperability updates for JavaScript: Introducing Kotlin’s latest interoperability update between JavaScript and Kotlin/Wasm. The Kotlin/Wasm feature is experimental, so there are some limitations.
- Dynamic types restricted: As of Kotlin version 1.9.0, Dynamic types are no longer supported in Kotlin/Wasm. JsAny now facilitates JavaScript interoperability instead of this deprecated type. You can find more information in the documentation of Kotlin/Wasm interoperability with JavaScript.
Improved Null Handling
With Kotlin 1.9.0, Kotlin’s null safety features have been enhanced. Using the new NullScope API, developers can fine-tune null safety settings, allowing more control over code scoping and nullability handling.
Conclusion
With Kotlin 1.9.0, this popular programming language achieves a desirable stage. This language has lots of surprises for you from offering multi platform support, Null Handling to variou compiler updates that makes developing high quality applications.
Hire Kotlin Developer to stay on top of the key highlights and create top of line applications.