Paul Krill
Editor at Large

Kotlin 1.4-M2 brings standard library improvements

news
May 13, 20202 mins

Next Kotlin 1.4 milestone release features API improvements and new functions for arrays and collections

coffee cup - coffee beans - Java
Credit: Christoph

JetBrains is working toward the general release of Kotlin 1.4, an upgrade to the open source, general purpose language for JVM, Android, web, and native development that promises improvements to the standard library including the API.

In a bulletin posted on May 12, JetBrains detailed standard library improvements in the forthcoming Kotlin 1.4-M2 milestone release. An early version has been deployed to the Kotlin playground for developers to try out. Changes to the existing API are featured, including updating signatures and introducing new constants. Some functions have been relaxed to accept nulls.

For example:

val s: String? = null
println(s.toBoolean())  // false

(Note that Kotlin 1.3 will not compile this code.)

Other API-related code changes also are featured, such as SIZE_BITS and SIZE_BYTES, which are new constants in Double and Float. These contain the number of bits and bytes used to represent an instance of the type in binary form.

Also new in the Kotlin 1.4-M2 standard library:

  • The common library is gradually being extended to add missing functionality. The standard library can be used in “common” code, i.e. the code shared between different platforms — Android, iOS, JVM, or JavaScript.
  • New array functions in the standard library include shuffle(), which puts array elements in a random order, and onEach(), which performs the given action on each array element and returns the array itself. Also, functions have been added for sorting array subranges.
  • The collections API has been expanded to cover more real-life cases. A new set creation function, set()NotNull(), makes a set consisting of all the non-null items among the provided arguments. Also, runningfold() and runningReduce() were introduced as synonyms for scan() and scanReduce(), to be more consistent with related functions.
  • With property delegation improvements, complementary interfaces will work better, with a new PropertyDelegateprovider interface and ReadWriteProperty, now inheriting ReadOnlyProperty. In addition, a property can delegate its getter and setter directly into another property.

The first milestone of Kotlin 1.4 was released on March 23 with access instructions. It featured a more powerful type inference algorithm and compiler generating type annotations in the bytecode for Java 8+ targets.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author