Kotlin 1.0.4 is here

We’re happy to announce the release of a new bugfix and tooling update of Kotlin, version 1.0.4. This version brings many improvements related to the IDE and build tools, as well as JavaScript support.

Once again we’d like to thank our external contributors who implemented some of the features in this release, Kirill Rakhman and Yoshinori Isogai, as well as everyone who tried the EAP builds of 1.0.4 and sent us feedback.

You can find the full list of fixes and improvements in the changelog. Some of the changes deserve special mention:

Language Change: Assignment of ‘val’ in try/catch

In versions of Kotlin before 1.0.4, you could initialize the same val both in the try and catch branches of a try/catch statement. For example, the following code was allowed:

1

2

3

4

5

6

7

8

valx:Int

try{

x=1

}

catch(e:Exception){

x=2

}

In effect, a final variable could be assigned twice, and it was possible to observe two different values for it (for example, if the value in the try statement was captured in a lambda). In Java, the equivalent code is not allowed.

To maintain consistent semantics, the code which assigns the same val in both try and catch branches becomes a warning in Kotlin 1.0.4 and will become an error in version 1.0.5. In most cases, the code can be easily fixed by converting the code to an expression form, and the IDE will offer a quickfix to convert this code automatically. The above example would be converted to:

1

2

3

4

5

6

7

valx=try{

1

}

catch(e:Exception){

2

}

New Experimental Annotation Processing

Kotlin 1.0.4 includes a new experimental implementation of the annotation processing API. To enable it, add the following to your build.gradle:

apply plugin: 'kotlin-kapt'

You also need to remove the snippet that enables old annotation processing:

1

2

3

4

kapt{

generateStubs=true

}

The new annotation processing still has known issues and may not be compatible with all annotation processors. You should enable it only if you’ve run into problems with the default kapt annotation processing implementation.

JavaScript Backend Improvements

The JavaScript backend can now compile code to modules which are compatible with AMD, CommonJS and UMD module systems. See the documentation for more details.

In addition to that, a limited form of reflection is now supported: you can use the jsClass property to access the runtime class of any object, and jsClass<TypeName>() to get the runtime representation of a specific class. Here’s a more complete example:

1

2

3

4

5

6

7

8

9

10

11

12

classA

classB

classC

inline fun<reifiedT>foo(){

println(jsClass<T>().name)

}

println(A().jsClass.name)// prints "A"

println(jsClass<B>().name)// prints "B"

foo<C>()// prints "C"

Compiler Improvements

Better type inference for callable expressions

More efficient bytecode for several cases of when and for expressions

Better parser recovery after syntax errors

Fixed several cases when “Cast never succeeds” warning was incorrectly reported

Build Tools Improvements

Full compatibility with Gradle 2.14 and later.

Gradle incremental compilation can now track changes between subprojects.

CLI and Ant builds add the Kotlin reflection library to the classpath by default; use the no-reflect switch to disable.

New Features in the IDE

You now have the option to use Kotlin syntax when evaluating expressions and watches in Java files

7 Responses to Kotlin 1.0.4 is here

I want to point out that 1.0.4 contains an important fix for an auto-completion bug that caused some severe freezing in Android Studio. Nikolay Krasko from JetBrains was instrumental in fixing this issue, and it has drastically improved my day-to-day experience in writing Kotlin. Thanks Nikolay and JetBrains!