Kotlin 1.1 has reached beta
Kotlin 1.1 has reached beta. Let’s see what’s coming (fairly soon!) in 1.1.
Kotlin 1.1 is not ready yet but it’s coming “fairly soon.” How do we know that? Kotlin 1.1 has finally reached beta.
According to the official announcement, the biggest highlights of 1.1 are the following: coroutines on the JVM, JavaScript and Android, as well as full support of compilation to JavaScript.
Kotlin 1.1 Beta Is Here!https://t.co/2mR7V6WC1m pic.twitter.com/1ObbHoOhhC
— Kotlin (@kotlin) January 19, 2017
But that’s not all: other features and language improvements are coming such as:
- Type aliases:
typealias Action<T> = (T) -> Unit
- Bound callable references:
expr::foo
- Type inference based on getters:
val myString get() = "hi"
- Compiler plugins for
- making classes
open
by default - generating no-arg constructors by default
- extension lambdas in SAM conversions
- making classes
- Inheritance for
data
classes - Subclasses of
sealed
classes in the same file - Destructuring in lambdas:
map.forEach { (k, v) -> ...}
- Underscore for unused parameters
- Scope control for builder-like DSL’s:
@DslMarker
provideDelegate
operator convention- Local delegated properties
- JDK 8 methods on Kotlin collections:
list.parallelStream()
- Inline properties
enumValues()
/enumValueOf()
for generic access to enums- Underscore in numeric literals:
1_000_000
Coroutines
Coroutines are about async/await, generate/yield, non-blocking IO, Rx and much more brought under the single unified paradigm of a suspending function. Such a function (or lambda) represents a computation that can be suspended (without blocking any threads) and resumed later, Andrey Breslav, Project Manager of Kotlin, wrote in the blog post announcing Kotlin 1.1 Beta.
future { val original = asyncLoadImage("...original...") // creates a Future val overlay = asyncLoadImage("...overlay...") // creates a Future ... // suspend while awaiting the loading of the images // then run `applyOverlay(...)` when they are both loaded return applyOverlay(original.await(), overlay.await()) }
According to Breslav, flexibility is the main benefit of coroutines. The language part is minimal, everything can be written as a library and libraries are in total control of all aspects of suspending and resuming computations: threads, exceptions and other aspects of computation are entirely customizable.
Kotlin coroutines will be released under an “experimental” opt-in flag, which means that the Kotlin team “is not committing to supporting the backwards compatibility of this feature after the final 1.1 release.”
Read more about coroutines here.
SEE ALSO: A first look at Kotlin 1.1
JavaScript
The full Kotlin language can be now compiled to JavaScript, Breslav announced in the blog post. However, this does not mean that they have ported all of the JDK into the browser; although the language and its Standard Library are not coupled with JDK, Kotlin strings, collections, sequences, arrays and other core APIs can be used on JS as well as JVM/Android.
The team will dedicate a lot of effort in Kotlin 1.2 and beyond to making the JavaScript tooling smooth and helpful, Breslav added.
Standard Library, tooling and frameworks
Kotlin’s Standard Library will include a variety of utilities and extensions including those specific for JDK 7 and 8. The collaboration with Gradle has resulted in gradle-script-kotlin, therefore users can now write type-safe build scripts for Gradle, using Kotlin scripting.
JSR 223 is now supported, which is utilized by the Spring Framework along with type-safe DSLs and other things.
You can find the entire list of new features here.