Programming language: Kotlin 1.5.30 prepares the desired language updates

By: MRT Desk

Published on:

Programming language: Kotlin 1.5.30 prepares the desired language updates

JetBrains has released version 1.5.30 of the Kotlin programming language. The release brings some language features planned for Kotlin 1.6, which are initially marked as a preview. These include sealed when-Instructions and the use of interrupting functions as a parent type.

The release can also be used natively on Apple’s M1 processors. Previously, Kotlin needed Rosetta to build and run applications on Apple Silicon. Kotlin 1.5.30 manages without the compatibility layer and knows the new target platforms macosArm64, iosSimulatorArm64, watchosSimulatorArm64 as tvosSimulatorArm64.

The sealed or exhausted when-Instructions have been wanted for a long time. Sealed in this case means that a branch must exist for all possible cases. When in doubt, one can else-Block cover all untreated cases. Version 1.6 of the programming language warns of not exhausted whenInstructions, and from Kotlin 1.7 the compiler should display an error.

Currently, developers have to activate the warnings manually by setting the environment variable languageVersion on 1.6 set. The following example from the documentation shows the warning for an incompletely processed instruction:

val y: Boolean = true
when (y) {
    true -> println("true")
}
// WARNING: Non exhaustive 'when' statements
// on Booleans will be prohibited
// in 1.7, add a 'false' or 'else' branch instead

Another innovation is that interrupting functions are now allowed as a parent type. With suspend The functions marked can be used in concurrent programs to interrupt the execution of coroutines. For example, they can wait for a file to be transferred over the network without blocking the current thread. Kotlin has known the concept of coroutines since version 1.1.

For the following short example there is also the adaptation of the environment variable languageVersion on 1.6 necessary:

class MyClass: suspend () -> Unit {
    override suspend fun invoke() { TODO() }
}

At the language level, Kotlin 1.5.30 brings additional rules for opt-in annotations and an extended type inference for recursive generic types.

Kotlin / Native offers integration with CocoaPods, the dependency manager for Swift and Objective-C. A Plug-in ensures interaction with the Gradle build tool. The current release of the programming language extends the DSL format and introduces new parameters to configure the plug-in. Among other things, the Kotlin DSL can now be used to specify the dynamic or static version of the framework and explicitly specify export dependencies.

The IR compiler backend (Intermediate Representation) introduced in version 1.4, which offers a uniform basis for the intermediate code during compilation, has now achieved beta status for Kotlin / JS, while it has been in beta status for the Java Virtual Machine (JVM) since version 1.5 is considered stable.

Another innovation concerns the joint use of platform-dependent libraries for several native targets in multi-platform projects. While so far only the libraries delivered with Kotlin / Native could be shared, version 1.5.30 allows sharing of libraries that are in cinteropsBlock of the build script are defined. The block contains the configurations for C, Objective-C and Swift libraries.

The programming language celebrated its tenth birthday on July 19th. In the beginning, Kotlin was limited to the Java Virtual Machine (JVM). It has started a triumphant advance on Android in particular since Google officially included it in Android Studio as an alternative to Java in 2017 and declared it the first choice for the mobile operating system two years later. In the meantime, however, the programming language has been designed for various platforms: Kotlin / Native enables execution without a virtual machine, especially to cover platforms such as iOS that do not have a JVM on board by default.

With Kotlin / JS a connection to JavaScript is also available, and since Kotlin 1.2 it is possible to create multi-platform projects that cover JVM and JavaScript with a code base. The language owes its name, which in this country likes to attract trolls in forums, to an island off St. Petersburg. The JetBrains team there was instrumental in developing Kotlin in the beginning.

Kotlin 1.5.30 is planned to be the last incremental release in the 1.5.x series. JetBrains changed the release cycle in October 2020, in which a feature release appears every six months, and version 1.6 is planned for November.

Let more details can be found on the Kotlin blog. IntelliJ IDEA should automatically suggest an update to the current version. The same applies to the IntelliJ IDEA based Android Studio.


(rme)

Article Source