The next big release from Kotlin is here! Kotlin 1.2 is a major step forward with a bunch of cool new features, including code-sharing between platforms. Let’s take a look at what’s in this new release.
The next major Kotlin release has arrived! This is a major step forward for Kotlin 1.2, which boasts operability across platforms as well as improved compilation times and library improvements. This time around, the key word is compatibility.
Let’s take a closer look at what’s in this latest version.
A multiplatform project consists of three types of modules:
- A common module contains code that is not specific to any platform, as well as declarations without implementation of platform-dependent APIs. Those declarations allow common code to depend on platform-specific implementations.
- A platform module contains implementations of platform-dependent declarations in the common module for a specific platform, as well as other platform-dependent code. A platform module is always an implementation of a single common module.
- A regular module that targets a specific platform. It can either be dependencies of platform modules or depend on platform modules.
To call platform-specific code from a common module, you can specify expected declarations – declarations for which all platform-specific modules need to provide actual implementations.
This feature also includes extra library support to move more logic to the common code.
kotlin.test, included out of the box in Kotlin 1.2, lets you write your test once and run it under both the JVM and JS;
kotlin.htmlsupports isomorphic rendering – using the same code to render HTML in the backend and in the frontend;
kotlinx.serializationallows you to easily marshal Kotlin objects between different tiers of your application, using JSON or ProtoBuf as serialization formats.
While this is an experimental feature for Kotlin 1.2, it’s an exciting one to see where it may go. Check out the documentation for more information.
Improved compilation speed
It’s not a major update without improving the speed. While developing 1.2, the Kotlin team tried to make the compilation process faster. They managed to achieve an impressive 25% improvement over Kotlin 1.1, with room for growth in future 1.2.x updates.
Kotlin 1.2 also boasts a number of other small improvements to the language and standard libraries.
- Backwards compatibility across Kotlin 1.0 and 1.2.
- A more concise syntax for passing multiple arguments to an annotation (array literals)
- Support for the
lateinitmodifier on top-level properties and local variables, as well as checking whether a
lateinitvariable is initialized
- Smarter smart casts and improved type inference in certain cases;
- Compatibility of the standard library with the split package restrictions introduced in Java 9;
kotlin.mathpackage in the standard library
- New standard library functions for working with sequences and collections, including a set of functions for breaking a collection or sequence into potentially overlapping groups of a fixed size.
More new features can be found here.
How to get Kotlin 1.2
You can try Kotlin online here.
- In Maven, Gradle and npm: Use
1.2.0as the version number for the compiler and the standard library. See the docs here.
- In IntelliJ IDEA: 2017.3 has Kotlin 1.2 bundled, in earlier versions Install or update the Kotlin plugin to version 1.2.
- In Android Studio: Install or update the plugin through Plugin Manager.
- In Eclipse: install the plugin using Marketplace.
- The command-line compiler can be downloaded from the Github release page.