What’s new in Kotlin 1.3

Kotlin 1.3 introduces contracts to the type system

What’s new in the Kotlin programming language
geralt (CC0)

The production version of Kotlin 1.3 is now available and introduces contracts to the type system.

Kotlin had its origins as a language for the JVM but has since been expanded to compile to JavaScript as well. Google has endorsed Kotlin as a mechanism for building Android mobile applications, alongside Java itself. 

Where to download Kotlin

You can access the Kotlin source code on the project’s GitHub repo.

Current version: What’s new in Kotlin 1.3

Kotlin 1.3’s contracts are an experimental addition meant to enrich the type information available through the function system with additional meanings useful at the call site. A contract lets a function tell the compiler things such as “I affect smart casts this way” or “I execute this lambda exactly once.” The Kotlin standard library already has contracts added to several functions, which work regardless of experimental flags.

Other new features in Kotlin 1.3 include:

  • The coroutines capability is in stable status, meaning there have been changes in the APIs and ABIs based on feedback. There is migration support to bridge old, experimental coroutines with new ones. Also, introspection is supported for suspend functions: isSuspend, KCallable.callSuspend, and KCallable.callSuspendby.
  • In the standard library, support has been improved for unsigned integer types. Unsigned types and arrays should feel more like first-class citizens.
  • With an API improvement in the standard library, the Random class introduced in the previous beta has gained extensions to generate unsigned numbers and arrays and unsigned bytes. Also, an extension called random() is being introduced for collections, arrays, and ranges to obtain a random element from elements of that collection, array, or range.
  • An API has been added to kotlin-reflect that can enumerate direct subtypes of a sealed class, namely sealedsubclasses.
  • Automatic mangling is being introduced for names of functions that use inline classes in their signatures. This prevents platform signature crashes when there are several overloads that are different just in the inline type but not in the carrier type. Mangling also forbids accidental use from Java, which may be undesirable because inline classes are a purely Kotlin concept.
  • Support for older source language versions is being deprecated, through the -language-version- flag with values 1.0 and 1.1 for kotlinc-1.3 and above. This change only affects compilation of source code for old target versions.
  • Code can be compiled to native binaries, via a beta of Kotlin/Native. Kotlin/Native uses LLVM compiler technology to compile Kotlin sources to standalone binaries for iOS, Linux, Windows, MacOS, and WebAssembly.
  • Multiplatform capabilities let business logic be shared among components on supported platforms, such as Android and iOS.
  • Kotlin 1.3 Tools for Kotlin/Native and multiplatform projects, available in the community and ultimate editions of the JetBrains IntelliJ Idea IDE, as well as in the Android Studio IDE. For Android Studio, use Plugin Manager to upgrade to Kotlin 1.3.
  • A sequence debugger to visualize lazy computations.
  • Experimental support for unsigned integers, which can assist with byte manipulation and other low-level code.
  • Experimental support for inline classes, for performance and type safety.

Previous version: What’s new in Kotlin 1.2

Kotlin Version 1.2 offers an experimental feature enabling reuse of code across platforms, as well as compatibility with the Java 9 module system. The latest version is Kotlin 1.2.50.

What’s new in Kotlin 1.2.50

Kotlin Version 1.2.50, released in June 2018, includes an experimental beta of improved scripting capabilities, along with library updates.

New library features include:

  • A beta set of toString(radix: Int) extension functions for Byte, Short, and Int. These are ready for use in experimental multiplatform projects and projects that target JavaScript.
  • The new String(chars: CharArray) and String(chars: CharArray, offset: Int, length: Int constructors convert Charray to String.
  • The testlibrary supports testing with the JUnit 5 framework, via the separate kotlin-test-junit5module.

The beta scripting features include:

  • For .jar files, developers now can create a file defining a script and if that .jar is added to the compilation classpath, scripts of this type are automatically supported by the compiler and IntelliJ Idea IDE plugin.
  • Typed external variables can be passed to the script compilation, making them accessible as if they were global variables defined outside of a script.

Other new features include:

  • Support for Kotlin 1.2.50 compiler by the new Version 0.85 of the JetBrains’s Eclipse plugin. The plugin also supports preferences in configuring generated JVM bytecode and has bug fixes in the debugger. The plugin is available in the Eclipse Marketplace.
  • You can more quickly build multimodule Android projects with the Gradle build system.
  • A beta progressive compiler mode is available for actively developed codebases whose maintainers regularly update to the latest versions of Kotlin’s compiler and tools. This beta mode can break some code due to its deprecations and bug fixes for unstable code.
  • Experimental @JvmDefault support has been updated with a binary compatibility mode. @JvmDefault is used for generating default methods for JVM interfaces.

What’s new in Kotlin 1.2.30

The 1.2.30 update released in March 2018, provides changes to the standard library as well as bug fixes. The update is compatible with multiple versions of the JetBrains IntelliJ Idea and the Android Studio 3.0 IDEs.

Its new capabilities include:

  • A new declaration in the library imitates the suspend modifier for lambda expressions.
  • Android modules are now supported in multiplatform projects.
  • The TestNG testing framework has been added to test.
  • The kapt annotation processing capability has been extended with error-reporting. It also adds proper links to original Kotlin declarations.
  • New inspections have been added to the IntelliJ IDE plugin, and performance has been improved as well. The plugin also has bug fixes.
  • Kotlin’s compiler has had bugs fixed and performance improved. To provide for more-efficient compiled code, the compiler now can optimize a tail call made in a suspending function to another Unit-returning suspending function.

What’s new in Kotlin 1.2.20

With the 1.2.20 update released in January 2018, Kotlin adds several capabilities ranging from use of the Gradle build system to building Android mobile applications. Described as a bug fix and tool update, version 1.2.20 includes:

  • Gradle build cache support.
  • Support for the development mode in the JavaScript DCE (dead code elimination) Gradle task.
  • Performance improvements as well as new inspections and bug fixes in the IntelliJ Idea plugin for Kotlin.
  • Improvements to incremental compilation for Android and mixed Java/Kotlin projects.
  • IDE backing for the new Kotlin style guide, which covers formatting of code and idiomatic use of language and library capabilities.

This update is compatible with IntelliJ Idea IDE from 2017.1 to 2017.3. It also works with the Android Studio IDE versions 3.0 and 3.1.

What’s new in Kotlin 1.2.00

Released in November 2017, Kotlin 1.2’s experimental multiplatform projects capability lets developers reuse code between supported target platforms: JVM and JavaScript initially, and later native. Code to be shared between platforms is placed in a common module; platform-dependent parts are put in platform-specific modules. During compilation, code is produced for both the common and platform-specific parts.

Developers can express dependencies of common code on platform-specific parts via expected and actual declarations. This declaration specifies an API, while an actual declaration is either platform-specific to the API or a type alias that refers to an existing implementation of the API in an external library. The standard library, meanwhile, features the kotlin.math package for performing mathematical operations in cross-platform code.

The kotlin.math package also now offers better precision for math polyfills for JavaScript.

Kotlin 1.2’s standard library is compatible with newly introduced Java 9 module system, which forbids split packages (multiple .jar files declaring classes in the same package). In Kotlin 1.2, the kotlin-stdlib-jdk7 and kotlin-stdlib-jdk8 artifacts replace the old kotlin-stdlib-jre7 and kotlin-stdlib-jre8.

Also to support Java 9, Kotlin 1.2 also removes the deprecated declarations in the kotlin.reflect package from the kotlin-reflect library. Developers need to switch to using the declarations in the kotlin.reflect.full package, which debuted in Kotlin 1.1.

Type inference improvements in Kotlin 1.2 include enabling the compiler to use information from type casts in type inference. If a developer calls a generic method that returns a type parameter, such as T, and casts the return value to a specific type, such as Foo, the compiler now understands that T for this call needs to be bound to the type Foo. This is especially important for Android developers, for the Kotlin compiler to correctly analyze findViewById calls in Android API Level 26. Also, the compiler now has an option to treat all warnings as errors.

Kotlin 1.2 also has these enhancements:

  • It now supports array literals in annotations, simplifying coding.
  • It uses a more consistent syntax.
  • The new reflection API lets developers check whether a lateinit variable has been initialized.
  • The lateinit modifier now can be used on top-level properties and local variables.

Copyright © 2018 IDG Communications, Inc.