Kotlin 1.7.20 programming language brings open intervals and compiler plugins

0
18
1664578592 kotlin 1720 programming language brings open intervals and compiler plugins.jpg
1664578592 kotlin 1720 programming language brings open intervals and compiler plugins.jpg

A new operator shows open ranges at the top, and the K2 compiler introduced in 1.7 gets plugins with which it connects Project Lombok, among other things.

Three months after Kotlin 1.7, version 1.7.20 of the programming language has now been released. The release brings a syntactic innovation for open-ended ranges and opens the compiler K2 for plug-ins. Additionally, memory management for Kotlin/Native, introduced in the previous release, is now enabled by default.

 

With regard to the syntax, the release brings only one noteworthy addition: the operator ..< indicates an open-ended range. The values ​​in the interval are at least as large as the start and smaller than the end:

 

when (value) {
    in 0.0..<0.5 -> // offener Range: ohne 0.5
    in 0.5..1.0 ->  // geschlossener Range: mit 1.0
}

 

With the new operator, Kotlin’s standard library also receives an addition: the interface OpenEndRange<T> is also the counterpart to ClosedRange<T> how ..< the opposite of the closed one .. is.

The K2 compiler is one of the biggest innovations in Kotlin 1.7. However, it didn’t work with compiler plugins on the first serve. That changes in the current release, even if K2 still has alpha status. The compiler can initially use seven plugins, including the extension for Project Lombok.

Kotlin has been able to work with the Java library since version 1.5.20. Project Lombok takes care of generating boilerplate code at the bytecode level: through the annotation @Data Lombok creates getters and setters, among other things, under the hood. The compiler plugin does not replace the Lombok library, but takes care of the clean interaction when using the library for mixed Java and Kotlin code.

Other plugins for K2 include all-open an extension that allows Kotlin to interact with frameworks like Spring AOP (Aspect Oriented Programming) that require open classes. Because Kotlin’s classes and their methods by default final are, they require explicit markup as open. That all-openplugin annotates classes and their members as open, so no manual insertion of open is required.

Besides the compiler, Kotlin 1.7 replaced the memory manager for Kotlin/Native applications running without a JVM. In version 1.7.20 it is now enabled by default and transitioning from alpha to beta status. Among other things, it brings advantages for concurrent programming by removing restrictions on the sharing of objects between threads.

Most notably, the new storage manager aims to open the door to Kotlin Multiplatform Mobile, which is designed for cross-platform mobile development for Android and iOS. Kotlin uses the JVM on Google’s operating system, which is missing on iOS, which is why the applications are implemented in Kotlin/Native. With the connection to the new memory manager, Kotlin Multiplatform Mobile will soon receive beta status.

JetBrains originally developed the Kotlin programming language for the Java Virtual Machine (JVM). It has been particularly successful on Android 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, which do not have a JVM on board.

A connection to JavaScript is also available with Kotlin/JS, and since Kotlin 1.2 it is possible to create multiplatform projects that cover JVM and JavaScript with a code base. The name, which likes to attract trolls in forums in this country, owes the language to an island off St. Petersburg. The JetBrains team there initially developed Kotlin significantly. In March, in response to the Russian war of aggression in Ukraine, JetBrains closed all Russian offices and relocated employees to other countries.

In 2020, JetBrains changed the release cycle for Kotlin. The company is scheduled to release a feature release with version 1.x every six months. Incremental releases with version number 1.x.y0 (1.7.10, 1.7.20, …) are scheduled to appear every two to three months, and bugfix releases with version number 1.x.yz (1.7.21 , 1.7.22, …).