Kotlin 2.0 introduces several key updates:
- IDE Support: Bundled Kotlin plugins in IntelliJ IDEA and Android Studio; K2 compiler is enabled by default.
- K2 Compiler: Stabilized for all target platforms with major performance improvements. Improved smart cast scenarios and multiplatform separation.
- Multiplatform: Enhanced separation of common and platform sources, and support for different visibility levels of expected and actual declarations.
- Compiler Plugins: Supports popular plugins like all-open, kapt, and serialization.
- Experimental Features: Power-assert plugin for better testing.
K2 Compiler
Kotlin 2.0 introduces many new features, with one of the biggest and most interesting being the K2 compiler. Now stable for all platforms, the K2 compiler offers significantly improved performance. Additionally, updates to plugins for IntelliJ IDEA and Android Studio make working with this version of Kotlin easier. The K2 compiler also enhances smart cast scenarios and the separation of multiplatform sources.
Smart cast improvements
In Kotlin 2.0.0, when using type checks with the or
operator (||
), the smart cast now targets the closest common supertype of the objects. Previously, the smart cast defaulted to the Any
type, requiring additional manual type checks to access properties or functions.
For detailed information visit: Smart cast improvements
Union types
As for union types, they will not be supported yet. It seems that in the future they will be, but only for exceptions. The way we know them from the TypeScript programming language, it appears that Kotlin will not support them.
This is a brief summary of the highlights from Kotlin version 2.
For detailed information, visit Kotlin 2.0.0 Documentation.