Releases

M6.1 Released

Two months ago we released M6 and we’re now ready with another update containing a bunch of goodies.

Language Improvements

There are several new language features and enhancements.

Improved Inference

Type inference now accounts for smart casts. As such the following will work correctly:

val map: Map<String, String> = ...

if (str != null) {
   map[str] = "Something"
}

Better Casting Diagnostics

The compiler is now smarter, catching impossible casts

val name: String = "Joe"
if (name is Iterable<*>) {
   ...
}

will give a compiler error.

Same way, casts for bare types can now be deduced

val values: Collection<String> = ...
if (values is List) {
   val name: String = values[0]
}

Also, else is no longer required in when clause when its return value is not relevant (i.e. it is used as a statement):

fun foo(x: Int) {
  when (x) {
     0 -> println("Zero")
     1 -> println("One")
  }
}

Suppress Warnings

You can decorate any declaration or expression with a suppress annotation (or hit Alt+Enter to let IntelliJ IDEA do it for you) so that the compiler no longer issues warnings inside it. This can be used for unchecked casts, renamed parameters and any other warnings.

[suppress("UNCHECKED_CAST")]
fun  foo(x: Any): T {
    return x as T
}

Local returns in lambdas

To avoid confusion, a bare return always means “return from a named function”. This means that in a lambda expression you are not allowed to say “return x” meaning that your lambda returns x. To mitigate this, you can now have labeled returns in lambdas. Say we have a higher order function named foo

fun foo(func: () -> Int) { ... }

we can call this passing a lambda that checks a condition and returns early

foo @myLambda { (): Int ->
   if (...)
       return@myLambda 10
   ...
}

The explicit labeling on the definition is not required, so the previous would be equivalent to:

foo { () : Int ->
   return@foo 10
}

Lambdas are automatically labeled after function they are passed to.

Note:The explicit return type in the lambda definition is a temporary requirement and will not be necessary in the future


Warning: Metadata format changed

We have made major changes to the binary format on the JVM, including decreasing the size footprint, increasing speed  and preparations for Reflection. Binaries compiled with older Kotlin versions will be incompatible.

JavaScript Support

Despite having a successful commercial product using Kotlin, and being compiled down to JavaScript, we have mostly been focusing our efforts on the JVM. That is until recently. We’re now pushing full  throttle with JavaScript support and with this release we add to the list of features provided, including:

  • Support for enums
  • Class Objects
  • Delegated properties
  • Multi-Declarations
  • SourceMaps

We’ve also deprecated support for ECMAScript 3 with this release.

Targeting JavaScript applications deserves more details and it is something we’ll be covering soon.

IDE Enhancements

We have a bunch more functionality in this release when it comes to IntelliJ IDEA support.

  • Convert member function to extension function
  • Navigation to getters and setters of a delegated property (Ctlr+click on by)
  • Navigation to iterator/next/hasNext in a for loop (Ctlr+click on in)
  • Navigation to invoke() from a call site (Ctlr+click on parentheses)
  • Improvements on Find Usages including support for constructors  and overrides

We’ve also improved project configuration including for Maven and Gradle based projects, including UI improvements, as well as some tweaking Completion.

Last but not least, this release also provides support for the newest EAP of IntelliJ IDEA 13 as well as the latest Android Studio.

You can find the Compiler and Plugins on our release page on GitHub. If you’re using IntelliJ IDEA, you can download the latest plugin from our repository or update it directly via Plugins in IntelliJ IDEA.

image description