Kotlin 1.6.0 released

JetBrains has Approved Kotlin 1.6.0 that ships with Kotlin 1.5.30 language and standard library features that are now available Stable. One of the new language features is sealed when Statement:

sealed class Employee {
    data class Developer(val languages: List) : Employee()
    data class Operations(val operatingSystems: List) : Employee()

fun printInformation(employee: Employee) {
    when (employee) {
        is Employee.Developer -> printLanguages(employee.languages)

Kotlin already offers verified when Expressions for sealed classes, enumerations, and boolean types for completeness. Use of a non-exhaustive when -Instruction leads to an error in Kotlin 1.7, but for the time being Kotlin 1.6.0 displays the following warning:

Non exhaustive 'when' statements on sealed class/interface will be 
prohibited in 1.7, add 'is Operations' branch or 'else' branch instead

Coroutines now support implementation suspend Function types as super types. Previously, it was only possible to use lambdas and expose function references for the desired behavior. Now a separate class can be used to implement the suspending function type:

class OrderManager : suspend () -> Unit {
    override suspend fun invoke() { ... }

fun buy(action: suspend () -> Unit) {}

Conversions from regular to suspending function types are now implicitly converted for any form of expression after they were previously restricted to functional literals and callable references. This makes it possible to use a regular function as a parameter for a suspending type:

val regularFunction = ::function

Type inference for recursive generic types is now possible based on the upper bounds of the type parameter.

Changes in the standard library include readln() as an alternative for readLine()!! which throws an exception at the end of the file. Similar, readlnOrNull() can be used as an alternative for readLine() which returns null when the end of the file is reached.

the typeOf() Function was already available as an experimental API for the JVM platform and is now officially available for all platforms.

Collection creators like buildList(), buildMap() and buildSet() are now stable and return serializable collections in their read-only state.

the duration API toComponents() Function now accepts a Long instead of a Int for the number of days to avoid problems with larger numbers. the DurationUnit enum is no longer a type alias for java.util.concurrent.TimeUnit on the JVM as it was not considered necessary. Extension properties such as Int.seconds are available through the Companion of the Duration Great to narrow its scope.

Other now stable features include rotateLeft() and rotateRight() for integer bit rotations, splitToSequence() which splits a string based on a regular expression, Comparable.compareTo() can now be used in infix notation and replace() and replaceFirst() now give the same results on the JVM and JS for group references.

With Kotlin 1.6.0 it is possible to develop based on the three previous API versions and the current stable version which currently includes 1.3, 1.4, 1.5 and 1.6.

Kotlins @kotlin.annotation.Repeatable is now compatible with Java and accepts retention and can be used repeatedly. Javas repeatable annotation also works in Kotlin.

A new experimental version that should only be used to evaluate the Storage manager is provided to remove the technical differences between native and JVM platforms. This enables a leak-free concurrent programming primitive without the need for annotations or other configuration from the developers. Kotlin / Native now also supports Xcode 13 and enables compilation of Windows targets on all hosts that support Kotlin / Native.

Downloads of Node.js and Yarn for Kotlin / JS projects can be disabled if they are already installed.

the Köver The Gradle plugin is now available for measure up Code coverage for Kotlin code created with the Kotlin JVM compiler. Before the Kover plugin was released, measuring code coverage was a challenge because, for example JaCoCo was not integrated into the Gradle toolchain and multi-platform projects.

The Kotlin documentation provides a complete overview, including examples of all changes in this version.

Comments are closed.