Kotlin 1.1-M02 is here!
We’re happy to announce the second milestone release of Kotlin 1.1. This release brings one long-awaited new language feature, destructuring in lambdas, as well as many improvements to features introduced in 1.1-M1, including type aliases, coroutines and bound references. The new release also includes all tooling features introduced in Kotlin 1.0.4 and 1.0.5-eap-66, and is fully compatible with IntelliJ IDEA 2016.3 EAP and Android Studio 2.2.
As with Kotlin 1.1-M01, we give no backward compatibility guarantees for new language and library features. Anything introduced in milestone releases of 1.1 is subject to change before the final 1.1 release.
And once again: please do share your feedback regarding the new language features or any problems that you may run into with this release, via YouTrack, forums and Slack.
The full changelog for 1.1-M02 is available here.
Destructuring in Lambdas
Kotlin 1.0 supports destructuring declarations – a feature that allows you to “unpack” a composite value (such as a data class) and assign its components to several distinct variables. Kotlin 1.1 extends this to lambda parameters, letting you unpack a composite variable passed to a lambda and access its components under distinct names. For example, you can use this to iterate over a list of pairs:
listOfPairs.map { (a, b) -> a + b }
You can find more details in the KEEP. Note that the feature is currently supported only for the JVM backend. Nested destructuring, as well as destructuring of arguments passed to regular functions and constructors, is currently unsupported.
Standard Library
Kotlin 1.1-M02 adds several new APIs to the standard library:
- distinct
AbstractCollection
andAbstractMutableCollection
hierarchies to use as base classes for implementing new Kotlin collection classes (KEEP-53); Map.toMap()
andMap.toMutableMap()
extension functions for copying maps (KEEP-13)
Reflection
The reflection library has gained a substantial amount of new features. You can now obtain more useful information out of a KType instance and create custom KType instances, introspect modifiers on declarations, get superclasses or check subtyping, etc. To see what’s new you can scan down the following commit.
IDE
The IntelliJ IDEA plugin has been extended to support the new 1.1 language features, with new refactorings “Introduce type alias” and “Inline type alias”, an intention action to create a type alias from usage, as well as quickfixes to apply destructuring in lambdas automatically.
Scripting
Starting with this release, Kotlin supports JSR-223 (the javax.script
API), allowing you to easily run Kotlin scripts from your application and to use Kotlin as an embeddes scripting language. It also continues the work required to support Kotlin scripting in Gradle build files.
JavaScript
JavaScript support in 1.1-M02 has been extended to support type aliases and class literals (Foo::class
).
In addition to that, we’re working to make more of the Kotlin API available in multiplatform projects. To that end, we’ve defined all the standard exception classes in the kotlin
package. When targeting the JVM, the Kotlin exceptions are defined as type aliases for the corresponding Java exceptions, and the JS backend provides their full-fledged implementations. We’ve also provided a full Kotlin implementation for the standard collection classes, which is now used in JS projects. (Kotlin on the JVM still uses standard Java collection classes.)
How to Try It
In Maven/Gradle: Add http://dl.bintray.com/kotlin/kotlin-eap-1.1
as a repository for the build script and your projects; use 1.1-M02 as the version number for the compiler and the standard library.
In IntelliJ IDEA: Go to Tools → Kotlin → Configure Kotlin Plugin Updates, then select “Early Access Preview 1.1” in the Update channel drop-down list, then press Check for updates.
On try.kotlinlang.org. Use the drop-down list at the bottom-right corner to change the compiler version to 1.1-M02.
With SDKMan. Run sdk install kotlin 1.1-M02
.
If you are using kotlinx.coroutines library please use updated version 0.1-alpha-2, it’s almost the same, but it’s recompiled with 1.1-M02 compiler. You can follow the updates in the readme file.
Have a nice Kotlin!
Lingchao Xin says:
October 20, 2016Congratulations, a quick question : When will be 1.1 final released ?
Sebastian Millies says:
October 21, 2016I cannot download kotlin-maven-plugin-1.1-M02.jar in my company, because a virus signature is detected:
Threat: EXP/2012-1723.DX.1
Details: Contains detection pattern of the exploits EXP/2012-1723.DX.1
URL: http://dl.bintray.com/kotlin/kotlin-eap-1.1/org/jetbrains/kotlin/kotlin-maven-plugin/1.1-M02/kotlin-maven-plugin-1.1-M02.jar
M01 is OK. Is this a known false positive?
ترجمه کلمه says:
October 22, 2016many thanks
jblaszczyk says:
October 29, 2016superb, but how about the promised TypeScript-to-Kotlin converter? I’d like to start using Kotlin for JS projects but it’s too limited now without some automated integration with existing JS stuff. do you still have this tool on your roadmap?
Zalim Bashorov says:
October 31, 2016Hello,
Unfortunately, TypeScript-to-Kotlin converter is not ready yet (for production), but it’s still in our roadmap. You can try it now https://github.com/bashor/ts2kt.
And feel free to ask any questions about it.
raincole says:
November 2, 2016Does Kotlin 1.1 still compile to Java 6 bytecode? I ask this because (I assume that) coroutine uses CompletableFuture, which is a Java 8 feature. How can it work on JVM 6?
Andrey Breslav says:
November 3, 2016That is a part of the library. On Java 6 this part is not present.
raincole says:
November 3, 2016So if my target Android API level is less than 24(CompletableFuture was added at level 24 iirc), I cannot use kotlin’s coroutine? It’s a bummer ;(
Andrey Breslav says:
November 4, 2016Why, you can use coroutines, but can not use the part of the library that depends on CompletableFuture. Other coroutine-based libraries will work for you.
Consider this Android-enabled library, for example: https://github.com/metalabdesign/AsyncAwait
Sebastian says:
November 4, 2016I am a bit confused about the relation between Kotlin language (what the compiler does) and what is added as library. Let me dexfibe my understanding and add a few questions.
As I understand the description at https://github.com/Kotlin/kotlin-coroutines/blob/master/kotlin-coroutines-informal.md#implementation-through-state-machines
Kotlin compiler will compile coroutines to a state machine. Neither the compiler nor the state machine rely on Java 8 constructs, and you can use coroutines with Java 6 (or corresponding Android API level).
Then there is the Kotlin standard library and kotlinx-coroutines and others. These libraries may define async/await and similar methods, which are not built into Kotlin, every library designer can cook their own. Some of these libraries may depend on Java 8, some – as the one you just mentioned – may not.
Also, I believe kotlinx-.coroutines relies on CompletableFuture, at least in part.
Have I understood all of this correctly? Is there another place where this is explained?
Also, will kotlinx-coroutines stay a separate library, or will it become part of the standard library?
Andrey Breslav says:
November 7, 2016Yes.
Not sure. We probably make it more clear in the future publications.
We’ll see, not sure yet. But in any case there will be a version of kotlin-stdlib compatible with pre-Java8 SDKs
Daniel Alves says:
November 7, 2016Just for curiosity. While I had look at the samples of the Coroutines and Async, for Kotlin 1.1, I have some questions about the design of this new feature.
It will work like Computed Expression of F# or just as a syntactic sugar like in C#?
Daniel Alves says:
November 7, 2016I just found https://github.com/Kotlin/kotlin-coroutines/blob/master/kotlin-coroutines-informal.md