Kotlin 1.5.30, just published by JetBrains, offers experimental new language features and experimental additions to the standard library. The experimental features include sealed
when statements and instantiation of annotation classes, which could become official in the upcoming Kotlin 1.6.0 release.
when statements, if enabled, introduce a compiler warning if a
when statement is not exhaustive. This is intended to make code safer without developers needing to introduce their own functions.
Also being previewed is support for
suspend functions as supertypes, enabling the use of
suspend functional types as super interfaces, although there are limitations, such as developers not being able to use multiple
suspend functional supertypes. This has been considered a missing piece in Kotlin coroutines design.
Installation instructions for Kotlin 1.5.30 can be found at blog.jetbrains.com. Kotlin 1.5.30 was unveiled August 24. Other improvements include:
- For Kotlin/JVM, instantiation of annotation classes lets developers call constructors of annotation classes in arbitrary code to obtain a resulting instance. Developers must enable this experimental feature to use it. Kotlin/JVM also now allows developers to specify whether the compiler reports a nullability mismatch based on information from specific types of nullability annotations.
- Native support is provided for Apple Silicon computers.
- As a step toward opt-in annotations pertaining to the standard library, new rules are offered for using and declaring opt-in requirement annotations on different targets.
- For the standard library, improvements have been made to
Regexstdlib APIs. The output of
Duration.toString()is now more readable, for example. The
DurationAPI will be stabilized in Kotlin 1.6.0.
- With type inference on recursive generic types enabled, the compiler can infer a type argument based on upper bounds of the corresponding type parameter if it is a recursive generic. This enables building of patterns with recursive generic types, often used in Java to make builder APIs.
- Elimination of builder inference restrictions lets developers specify the type information that the builder inference can infer as well as use the
getfunction on the builder inference.
- Improvements have been made to Kotlin Multiplatform including the ability to use
cinteroplibraries in shared native code, extending the sharing of platform-dependent libraries shipped with Kotlin/Native. Also, there is a new default publishing setup for Android artifacts.
- New experimental functions are provided for regular expressions, including
matchesAt(), to check whether a regex has a match in the specified position of a string.
- For Kotlin/JS, the IR compiler back end moves to a beta stage.
- For the Gradle build tool, the plug-in user experience has been improved.
Kotlin 1.5.30 is slated to be the last incremental release of the language before Kotlin 1.6.0. Kotlin 1.5.20, which emphasized coding enhancements, arrived in late-June.
Copyright © 2021 IDG Communications, Inc.