What’s new in Kotlin 1.2? Code reuse, for starters

The Kotlin 1.2.30 update provides changes to the standard library as well as bug fixes

What’s new in Kotlin 1.2? Code reuse, for starters
geralt (CC0)

Version 1.2 of the statically typed Kotlin language, a version of Java endorsed by Google for Android app development, offers an experimental feature enabling reuse of code across platforms, as well as compatibility with the Java 9 module system.

Where to download Kotlin 1.2

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

What’s new in Kotlin 1.2.30

The 1.2.30 update released on March 1, 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 January 17, 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 on November 29, 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.

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

This story, "What’s new in Kotlin 1.2? Code reuse, for starters" was originally published by InfoWorld.

Shop Tech Products at Amazon