Java-alternative Kotlin 1.6 has been pushed into the open and provides developers with some stabilised language features, improvements to the standard library, and home-grown tooling to measure test coverage.
Kotlin has been around since 2010, but was first introduced by IDE developer JetBrains in 2011. Using the insight gained in building and maintaining Java IDE IntelliJ IDEA, the company wanted to use Kotlin to tackle Java shortcomings and come up with a more concise language. Compared to JVM-language Scala, which appeared a couple of years earlier and had similar goals, Kotlin also looked to keep compile times at bay in order to stay competitive.
Growing adoption, however, comes with growing demands, and good code coverage surely is amongst the things enterprise users need to ensure their software’s quality. According to the Kotlin team, test coverage tools like JaCoCo admittedly work with the language, but integrating them into their Gradle toolchain or multi-platform projects still leaves a bit to be desired. A new Gradle plugin called Kover is meant to eliminate these deficiencies when working with JaCoCo or the IntelliJ IDEA Code Coverage Agent.
Kover promises to collect code coverage for JVM test tasks, generate XML and HTML reports, and offer customisable filters for instrumented classes. It is also supposed to work with Kotlin/JVM, Kotlin Multiplatform, and sources mixing Kotlin and Java without additional configuration necessary and support Kotlin Android “without dividing them into build types and flavours”.
The language itself gains in v1.6 a stable version of sealed exhaustive
when statements, amongst other things. The feature has been in the works since 2016 and now lets the compiler warn developers if their
when statements don’t take all necessary types in an app into account. The Kotlin team also improved type inference for recursive generic types, making the compiler better at inferring type arguments, and support for implementing suspend functional types as super interfaces to move coroutine design along.
Additionally, stabilisation of suspend conversions means that developers can now “pass any expression of a suitable regular functional type where suspending is expected as a parameter” and there’s a compiler option to write generic builders without special annotations.
Kotlin’s standard library has been fitted with new functions
readlnOrNull() that throw an exception or null respectively when reading from the console and reaching an end of line. There’s also no need to use
!! (not-null assertion operator) after reading a line from
stdin anymore, and the duration API,
typeOf(), collection builders, bit rotation operations on integers, and the
regex function for splitting strings into sequences have been stabilised.
Developers who use Kotlin for writing platform-specific native code can take the new memory manager for a spin. Though still experimental, the feature might be a good one to get familiar with for those looking to target both Android and iOS, since it lifts object sharing restrictions between threads which will help to make code run on both platforms.
More details on improvements, such as support for Xcode 13 and a unified compiler plugin ABI, can be found in the Kotlin blog.