Kotlin M5.1

There have been enough little improvements since Kotlin M5 so that we are rolling them out as M5.1 today. Some of them are not so little in fact, like enabling the use of Scala libraries, such as Akka. This post gives a quick overview of these changes.

Better Support for Scala Classes. Akka

Theoretically, it is very easy for all JVM languages to interoperate. In practice, there appear to be numerous little problems that make it unpleasant or practically impossible.

One of such problems was related to the ambiguous use of “$” signs in class names, which is a well-known issue on the JVM. It being fixed now, allows you to use some Akka classes you couldn’t use before, such as Duration.

To get an impression of what Akka looks like in Kotlin, have a look at this example.

Even More Helpful IDE

With the help of students of Cornell and Jagiellonian universities, we got quite a few quick fixes implemented in M5.1. When the IDE complains about some error or warns you, you can simply press Alt+Enter and get a list of proposed fixes:

Parameters are Immutable

We removed support for mutable parameters, as in

The main reason is that this was confusing: people tend to think that this means passing a parameter by reference, which we do not support (it is costly at runtime). Another source of confusion is primary constructors: “val” or “var” in a constructor declaration means something different from the same thing if a function declarations (namely, it creates a property). Also, we all know that mutating parameters is no good style, so writing “val” or “var” infront of a parameter in a function, catch block of for-loop is no longer allowed.

If some of your existing code breaks, you can quick-fix the whole project in one click using the IDE:

Support for Java’s protected static methods

Some Java frameworks, like Android, rely on protected static methods to be available in subclasses. Although this seems like a questionable pattern, Kotlin now supports it (only for Java compatibility), i.e. you can access a protected static member of a Java class if you extend this class in Kotlin.

Anonymous Objects

Consider the following code (that uses a Kotlin analog to anonymous inner class):

What is the type of x? It used to be the anonymous type, but if you use x from the outside, you can not access it: the type is not valid. Now the type will be A. This applies only to properties that can be seen from the outside, i.e. if x is a local variable it will still have the anonymous type, since it is harmless.

Class Objects are Usable from Java

Kotlin classes do not have static members, but rather have class objects:

Now, with a few bugs fixed, you can access members of class objects from your Java code:

Compiler

The compiler is being improved too: a few fixes for corner cases of nullable types interacting with generics and optimizations for loops over ranges.

Requirements

Kotlin M5.1 requires IntelliJ IDEA 12.0.4 (EAPs of 12.1 are not supported yet), you can download it from the plugin repository.

Have a nice Kotlin!

About Andrey Breslav

Andrey is the lead language designer working on Project Kotlin at JetBrains. He also works on making the Java language better, serving as a Java Community Process expert in a group for JSR-335 ("Project Lambda"), and occasionally speak at software conferences such as Devoxx or JavaOne.
This entry was posted in General and tagged . Bookmark the permalink.

2 Responses to Kotlin M5.1

  1. Andreas says:

    Maven version for Kotlin M5.1 is 0.5.162

  2. Daniel Alves says:

    Great news Andrey!

    I miss the var keyword in parameters but it is used in so little cases that I will not complain about it.

    I started to play again with kotlin in my projects using: JavaFx (and a special DSL), Hibernate and OSGI. I use Akka in some parts too, so this changes may correct some bugs before.

    Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">