Kotlin 1.4-M2 Features API Enhancements and New Functions for Arrays and Collections
JetBrains is advancing toward the general release of Kotlin 1.4, an upgrade to its open-source, multi-platform programming language used for JVM, Android, web, and native development. This upcoming release promises significant enhancements to the standard library, including updates to the API. The Kotlin 1.4-M2 milestone release has been detailed in a bulletin posted on May 12 and is now available in the Kotlin playground for developers to explore.
The Kotlin 1.4-M2 release introduces various improvements to the standard library, including changes to existing APIs and new additions. For instance, some functions have been updated to accept null values, addressing previous limitations. An example of this is shown with the toBoolean()
function, which now works with nullable strings
Additionally, new constants such as SIZE_BITS
and SIZE_BYTES
have been introduced in the Double
and Float
types. These constants provide the number of bits and bytes used to represent an instance of these types in binary form, adding useful information for developers working with data representation and memory management.
Kotlin 1.4-M2 also extends the common library, which supports code shared across different platforms such as Android, iOS, JVM, and JavaScript. This extension aims to add missing functionality and enhance compatibility across various environments. New functions for arrays, including shuffle()
and onEach()
, provide more flexibility for manipulating array elements. shuffle()
randomizes array elements, while onEach()
performs an action on each element and returns the array itself. The standard library now also includes functions for sorting subranges of arrays.
The collections API has been expanded to better handle real-world scenarios. The new set()NotNull()
function creates a set from non-null items among the provided arguments. Additionally, runningFold()
and runningReduce()
have been introduced as synonyms for scan()
and scanReduce()
, aligning with related functions for consistency.
Improvements to property delegation include the introduction of the PropertyDelegateProvider
interface and enhancements to ReadWriteProperty
, which now inherits from ReadOnlyProperty
. Properties can now delegate their getter and setter operations directly to another property, streamlining property management.
The first milestone of Kotlin 1.4 was released on March 23 and featured a more powerful type inference algorithm and improved bytecode generation for Java 8+ targets. These updates are part of JetBrains’ ongoing effort to refine Kotlin and provide a more robust development experience.