Kotlin 1.5.30 Introduces Sealed When Statements and Suspend Functions for Trial Run
Kotlin 1.5.30, recently released by JetBrains, introduces experimental new language features and additions to the standard library. These experimental features include sealed when statements and the instantiation of annotation classes, which could become official in the upcoming Kotlin 1.6.0 release.
Sealed When Statements
Sealed when statements, if enabled, introduce a compiler warning if a when statement is not exhaustive. This feature aims to enhance code safety without requiring developers to add their own functions to check exhaustiveness.
Suspend Functions as Supertypes
Kotlin 1.5.30 also previews support for suspend functions as supertypes. This allows the use of suspend functional types as super interfaces, although there are limitations, such as the inability to use multiple suspend functional supertypes. This feature addresses a gap in the Kotlin coroutines design.
Installation Instructions and Release Date
Kotlin 1.5.30 was unveiled on August 24. Installation instructions for this version can be found on the JetBrains blog.
Other Improvements
- Kotlin/JVM Enhancements
- Instantiation of annotation classes: Developers can now call constructors of annotation classes in arbitrary code to obtain a resulting instance. This experimental feature needs to be enabled.
- Nullability mismatch handling: Developers can specify whether the compiler reports a nullability mismatch based on specific types of nullability annotations.
- Native Support
- Native support for Apple Silicon computers has been added.
- Opt-in Annotations
- New rules are provided for using and declaring opt-in requirement annotations on different targets, moving toward opt-in annotations for the standard library.
- Standard Library Improvements
- Duration and Regex APIs: The Duration API has been improved for better readability in Duration.toString() output and will be stabilized in Kotlin 1.6.0.
- Type inference on recursive generic types: The compiler can infer a type argument based on the upper bounds of the corresponding type parameter if it is a recursive generic, enabling patterns often used in Java builder APIs.
- Elimination of builder inference restrictions: Developers can now specify the type information that builder inference can infer and use the get function on builder inference.
- New experimental functions for regular expressions, such as matchesAt(), to check whether a regex has a match in a specified position of a string.
- Kotlin Multiplatform
- Enhancements include the ability to use cinterop libraries in shared native code, extending the sharing of platform-dependent libraries shipped with Kotlin/Native, and a new default publishing setup for Android artifacts.
- Kotlin/JS
- The IR compiler back end has moved to a beta stage.
- Gradle Build Tool
- The plug-in user experience has been improved.
Future Releases
Kotlin 1.5.30 is expected to be the last incremental release before Kotlin 1.6.0. Kotlin 1.5.20, which focused on coding enhancements, was released in late June. The new features and improvements in Kotlin 1.5.30 are poised to enhance the language’s capabilities, making it more robust and developer-friendly.