In addition to a K2 interface for plugins, the release has a new memory manager for Kotlin/native on board and introduces open ranges.
Two months after version 1.7, the first beta of Kotlin 1.7.20 has now been released. The release expands the new compiler K2 with plug-ins that target, among other things, Project Lombok and non-final classes for frameworks. Also, memory management for Kotlin/Native introduced in 1.7 is enabled by default. Finally, there is a syntactic innovation for open-ended ranges.
Compiler with connector
Kotlin 1.7, released in June, introduced the new K2 compiler, which JetBrains says brings significant performance improvements. In version 1.7.20 it still has alpha status, but unlike the first launch, compiler plug-ins can now be used. First, he can work with seven extensions.
Among other things, the plug-in can be used to integrate Project Lombok. Kotlin has been able to work with the Java library since version 1.5.20. It takes care of generating boilerplate code at the bytecode level: through the annotation @Data
creates Lombok alongside getters, setters, equals, hash code and conversion to a string under the hood. As a result, the methods do not bloat the source code, but are available both during execution and in the development environment. The compiler plugin is not a replacement for 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. Kotlin’s classes and their methods are standard final
and require explicit markup as open
. That all-open
plugin annotates classes and their members as open, so no manual insertion of open
is required.
New memory management for native applications
The new memory manager introduced with the Kotlin 1.7 beta for Kotlin/Native applications running without the JVM is now enabled by default. Previously, developers had to select it manually. At the same time, it changes from alpha to beta status. Among other things, it brings advantages for concurrent programming by removing restrictions on the sharing of objects between threads. With the predecessor, these restrictions resulted, among other things, in the use of coroutines with the library kotlinx.coroutines
to problems.
The new storage manager is primarily intended to open the door for 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 of the new memory manager, Kotlin Multiplatform Mobile will soon receive beta status.
open end
As a linguistic innovation, the open ranges at the end are worth mentioning: The operator ..<
displays an open-topped interval that does not include the ending value: the values are at least as large as the starting value and smaller than the ending value, as in the following code snippet from the Kotlin documentation:
when (value) {
in 0.0..<0.25 -> // first quarter
in 0.25..<0.5 -> // second quarter
in 0.5..<0.75 -> // third quarter
in 0.75..1.0 -> // last quarter <- note closed range here
}
With the new operator, Kotlin’s standard library also receives an addition and now knows the interface OpenEndRange<T>
which is also the counterpart to ClosedRange<T>
is like ..<
the opposite of the closed one ..
is.
The programming language celebrated its eleventh birthday on July 19. In the early days, Kotlin was limited to 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, …).
More new features in version 1.7.20 can be found on the Kotlin blog. The beta version can be used with IntelliJ IDEA and the Android Studio based on it. If the update channel is under Tools | Kotlin | Configure Kotlin Plugin Updates on Early Access Preview is set, the IDE will automatically suggest updating to the latest beta.