Kotlin 1.7 beta

JetBrains has just released Kotlin 1.7 beta. The main new feature highlighted by JetBrains for Kotlin 1.7 is the evolution of type generator inference. This feature helps the compiler infer the type arguments of a call using type information about other calls inside its lambda argument.

With Kotlin 1.7 type builder inference is automatically enabled if a standard type inference cannot get enough information about a type without specifying the -Xenable-builder-inference compiler option, which was introduced with Kotlin 1.6. This means that you can now write your own builders that use type builder inference without applying any additional annotations or options.

Also note the return of the min() and max() collection functions. With Kotlin 1.4 these functions had been renamed minOrNull() and maxOrNull(). Kotlin 1.7.0 reintroduces the original function names, but with a non-nullable return type. These new min() and max() functions now strictly return the collection item or throw an exception.

fun main() {
val numbers = listOf()
println(numbers.maxOrNull()) // “null”
println(numbers.max()) // “Exception in… Collection is empty.”
}

Also note the possibility to try the alpha version of the new Kotlin/Native memory manager in Kotlin 1.7.0 beeta. This release brings performance improvements to the new memory manager that will improve the experience for developers.

The new memory manager eliminates differences between JVM and Native platforms. It provides a consistent development experience across cross-platform projects. For example, you’ll have a much easier time creating new cross-platform mobile apps that work on both Android and iOS, says JetBrains.

The new Kotlin/Native memory manager lifts restrictions on object sharing between threads. It also provides leak-free concurrent programming primitives that are safe and require no special management or annotation. The new memory manager will become the default in future releases.