Kotlin 1.2 M2 is out

We’re happy to announce the second milestone release for Kotlin 1.2. The primary focus of this release is concerned with stability and bugfixes in Kotlin compiler and tooling as well as improvements of Kotlin standard library. It also includes many of the tooling features available in the upcoming release of Kotlin 1.1.4.

We appreciate your feedback regarding the new features or any problems that you may run into with this release.

The complete changelog since 1.2 M1 can be found here with some major changes listed below.


Breaking change: Java-default method calls

Up to now Kotlin interface members overriding Java-default methods while targeting JVM 1.6 produced a warning on super calls: Super calls to Java default methods are deprecated in JVM target 1.6. Recompile with '-jvm-target 1.8'. In 1.2-M2 release we’ve replaced the warning with error, thus requiring any such code to be compiled with -jvm-target 1.8 option

Standard library

Revised windowed/pairwise operations

We have been listening to your feedback about chunked/windowed/pairwise functions KEEP-11, which were released to preview in the previous milestone 1.2-M1, and based on it we decided to make some changes to these functions:

  • windowed function now has its step parameter defaulting to 1.
    It also gets an additional optional parameter partialWindows, which controls what to do with incomplete windows in the end. By default it is false, which means incomplete windows are dropped.
  • pairwise function name was too confusing, it was unclear how it paired the elements together. Now it is called zipWithNext, so it is more clear that each element is zipped with the next element in a collection.

Common math operations in the standard library

There was a longstanding request to support math operations in the standard library KT-4900. Until now one had to resort to math functions and constants from java.lang.Math class in JVM platform and to kotlin.js.Math which exposed native JS Math functions to Kotlin code in JS platform.
But now we’re introducing the following groups of API in the kotlin.math package:

  • constants: `PI` and `E`;
  • trigonometric: `cos`, `sin`, `tan` and inverse of them: `acos`, `asin`, `atan`, `atan2`;
  • hyperbolic: `cosh`, `sinh`, `tanh`;
  • exponentation: `pow` (an extension function), `sqrt`, `hypot`, `exp`, `expm1`;
  • logarithms: `log`, `log2`, `log10`, `ln`, `ln1p`;
  • rounding:
    • `ceil`, `floor`, `truncate`, `round` (half to even) functions;
    • `roundToInt`, `roundToLong` (half to integer) extension functions;
  • sign and absolute value:
    • `abs` and `sign` functions;
    • `absoluteValue` and `sign` extension properties;
    • `withSign` extension function;
  • `max` and `min` of two values;
  • binary representation:
    • `ulp` extension property;
    • `nextUp`, `nextDown`, `nextTowards` extension functions;
    • `toBits`, `toRawBits`, `Double.fromBits` (these are in the `kotlin` package).

The same set of functions (but without constants) is also available for Float arguments.
Most of these functions (except the binary representation group) are also available in JS, thus solving the problem of writing the same calculations for both platforms.

Pre-release notes

As with other milestone releases, we give no backwards compatibility guarantees for new language and library features. Anything introduced in milestone releases of 1.2 is subject to change before the final 1.2 release. When we reach final RC, all binaries produced by pre-release versions will be outlawed by the compiler: you’ll be required to recompile everything that was compiled by 1.2‑Mx.
However all the code compiled by 1.1.x and earlier releases is perfectly fine without recompilation.

How to Try It

In Maven/Gradle: Add as a repository for the build script and your projects; use 1.2-M2 as the version number for the compiler plugin and the standard library.

In IntelliJ IDEA: Go to Tools → Kotlin → Configure Kotlin Plugin Updates, then select “Early Access Preview 1.2” in the Update channel drop-down list, then press Check for updates.

The command-line compiler can be downloaded from the Github release page.

On Use the drop-down list at the bottom-right corner to change the compiler version to 1.2‑M2 (coming soon).

Comments below can no longer be edited.

15 Responses to Kotlin 1.2 M2 is out

  1. Avatar

    elect says:

    August 9, 2017

    Just trying the awesome math package.. toDegrees and toRadians are missing…

  2. Avatar

    alanfo says:

    August 9, 2017

    Great news that the commoner math functions are to be integrated into the standard library which I’m sure will be appreciated by just about everybody! I have a few points though:

    Is there any point exposing min() and max() functions when we already have the more versatile minOf and maxOf functions in the standard library?
    A notable omission for me is the cube root function, cbrt(), which is in Java, JS and C/C++ and is used fairly often. It can admittedly be reproduced with the more long winded: d.pow(1.0 / 3.0) but not as nice as cbrt(d).
    I’d consider making the pow() extension function infix. We’d then be able to do the more natural: 3.0 pow 4.0 rather than just 3.0.pow(4.0).
    Agree with ‘elect’ that toDegrees() and toRadians() should be there.

    • Avatar

      João Vitor Verona Biazibetti says:

      August 9, 2017

      I agree.

      ‘pow’ really should be infix (as it is more “natural”, but if someone wants to use the normal function syntax, it’s still possible…).

      Also, min/max and minOf/maxOf work the same way (on JVM, they call java.lang.Math.max/min)… maybe it was overlooked?

      • Avatar

        MonkeyCoder says:

        August 23, 2017

        How about operator ^ like 3^4. Is there any other use of ^ ?

        • Avatar

          alanfo says:

          August 24, 2017

          Not currently, as the infix function ‘xor’ is used as the exclusive ‘or’ bitwise operator rather than ‘^’.

          However, the danger is that if ‘^’ were used as the power operator, then people might mistakenly think that it was the exclusive ‘or’ operator that were being used.

          For this reason a better choice would perhaps be ** like 3**4 which I’ve seen used in some other languages.

      • Avatar

        alanfo says:

        August 10, 2017

        Thanks for the link to KT-19578.

        I’m surprised at what Ilya Gorbunov said about infixing ‘pow’ as the difference in priority hasn’t stopped them from infixing the bitwise operators in the past. However, that’s another contentious issue at the moment. See for example:

  3. Avatar

    soywiz says:

    August 9, 2017

    Is there any reason to not expose Float/Double raw bit functions to kotlin.js? You can use typed arrays with a common buffer to implement them easily

  4. Avatar

    Lukáš Kúšik says:

    August 10, 2017

    Please add a sumByLong method on iterables.

  5. Avatar

    Stéphane Lavergne says:

    August 11, 2017

    Will the first stable 1.2 release include coroutines ready for production? I couldn’t find any clear roadmap on the matter and this will seal the deal for our projects (vs both Golang and ECMAScript 7).

    • Avatar

      Roman Elizarov says:

      August 28, 2017

      Coroutines are already ready for production. That was the whole purpose of releasing them in 1.1. We are actively gathering feedback and are working on improvements that might require us to change design a little bit in the future, so we’ll keep them experimental in 1.2 release. However, we are 100% committed to maintaining backwards compatibility and supporting your code. You can get more details on what that experimental status means in the end of this presentation:

      • Avatar

        Stéphane Lavergne says:

        September 5, 2017

        Thank you! I look forward to learning Kotlin, its coroutines and the JVM in the coming winter. 🙂

        If anyone is looking for the specific explanation about the experimental flag, it’s at 44:25 in the above video.

  6. Avatar

    Nick K says:

    August 14, 2017

    I’m curious if improvements to Kotlin Scripting (.kts files) is on the roadmap. Specifically around things like external dependency resolution or inclusion of other script files. I would love to use Kotlin to replace my system groovy scripts.

  7. Avatar

    Joemarie Amparo says:

    August 15, 2017

    Kotlin is definitely an exciting development and we have to see what the future brings in terms of adaption. Our Android guys recently spent a few weeks digging into the topic.