Paul Krill
Editor at Large

Kotlin update previews experimental features

news
Aug 27, 20213 mins

Kotlin 1.5.30 offers trial run of sealed when statements and suspend functions, language features that could be production-ready in Kotlin 1.60.

paper airplane getting off the ground test
Credit: Thinkstock

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.

Sealed 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 Duration and Regex stdlib APIs. The output of Duration.toString() is now more readable, for example. The Duration API 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 get function on the builder inference.
  • Improvements have been made to Kotlin Multiplatform including the ability to use cinterop libraries 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.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author