IntelliJ IDEA 11.1 has been recently released, and we are happy to announce a milestone candidate build for Kotlin IDE plugin, too. This post gives an overview of what happened over the last month.
Milestone Candidate Build is Ready for Your Evaluation
To install on IntelliJ IDEA 11.1 (Free Community Edition is available here), please follow the instructions from the Getting Started guide. In short:
- Use this plugin repository: http://www.jetbrains.com/kotlin/eap-plugin-repository/updatePlugins.xml
- Or download a zipped plugin from here.
You can always download nightly builds of Kotlin from our build server or build it yourself from sources.
Now we proceed to a short overview of the New and Noteworthy. Please refer to this blog post for the previously implemented features.
Little Things that Matter
First of all, we did very many bugfixes, improvements and other important things that are hard to demo. See the commit history on github and the closed issues in YouTrack.
Library
With the power of extension functions, Kotlin makes existing Java APIs better. In particular, we provide enhancements for JDK collections so that you can say things like this:
fun main(args : Array<String>) {
val list = arrayList(1, 2, 3)
val odds = list.filter {it % 2 == 1}
println(odds.join(", "))
}
Here, filter() and join() are extension functions.
Implementation-wise, extension functions are just static utility functions, like “good old” Java’s Collecions.*, but with the “receiver.function()” call syntax, the IDE makes them much better: there is code completion that helps you browse through the API and learn it (just as if the extensions were normal class members):
You can navigate to sources of library functions:
And see the doc comments there:
The HTML version of the library docs is available here.
GitHub Support
Kotlin highlighting is now supported by github, including gist.
Annotations
Kotlin now supports annotations. Here’s a small example that relies on JUnit 4:
import org.junit.Test as test
import org.junit.Assert.*
class Tests {
test fun simple() {
assertEquals(42, getTheAnswer())
}
}
Read more here.
String Templates
Now you can use multi-line string templates, for example:
println("""
First name: $first
Last name: $last
Age: $age
""")
Simple Enums
Simple cases of enum classes are now supported. For example:
enum class Color {
RED
GREEN
BLUE
}
Local Functions
Functions can be declared inside other functions:
fun count() : Int {
fun count(parent : Entity) : Int {
return 1 + parent.children.sum { count(it) }
}
return count(this.root)
}
Nullability
Kotlin now recognizes the @Nullable and @NotNull annotations). If the Java code says:
@NotNull String foo() {...}
Kotlin will trat foo() as returning a non-nullable String.
A short-hand operator (!!) for converting a nullable value into a non-nullable one is added:
val foo = getSomethingThatMayBeNull() foo!!.bar() // throw NPE if foo is null, run bar() otherwise
Byte Code Unveiled
Click on the Kotlin button on the right edge of the IDEA window, and choose the “Bytecode” tab. You’ll see the byte-code Kotlin generates for your program!




Thanks for this great work!
Failed to load descriptor.
(Mac Lion)
If ti’s from plugin manager, please re-try, or download the zip. We’ll try to fix this.
Resolved now
If foo!!.bar() raises NPE if foo is null, how exactly does that differ from simply calling foo.bar()?
After !!. operator was added to Kotlin program there’s no difference in behavior from foo.bar() call in Java. But the great difference was at previous step when compiler was able to find a place with probable NPE threat and asked programmer to resolve it explicitly.
You can find more information about null-safety feature in Kotlin on this wiki page.
So if I read that correctly, without !!, the compiler will fail on a possible null reference. But the !! tells the compiler to butt out and let it fail at runtime?
Yes you’re right. And this is the reason why !! calls should be used with great caution or avoided completely. If you are in Kotlin and not planning to assign null value to variable just declare it with not-nullable type. While working with methods and variables from Java it’s better to choose some safe way to deal with possible null value. It can be ?. call or pre-check to null.
Hey Charles,
Glad to see you here!
Guys, what you do is awesome!
Personally I’d switch to Kotlin right after first RC.
Thanks for the encouraging words!
Thank you guys, this is a brilliant work!
I’ll switch to Kotlin as soon as it gets Android support.
Also Kotlin has inspired me to switch to IntelliJ IDEA
Keep up the good work!
Thanks for the kind words!
How to use JUnit with kotlin? or how to have unit test with kotlin? Can you provide any example on it ?
I found compile speed will become very very slow, and KCompile will report the following error:
java.lang.IllegalStateException: Internal error: (14,72) java.lang.AssertionError
@ClosureAnnotator.java:112
at org.jetbrains.jet.codegen.CompilationErrorHandler$1.reportException(CompilationErrorHandler.java:27)
at org.jetbrains.jet.codegen.GenerationState.compileCorrectFiles(GenerationState.java:120)
at org.jetbrains.jet.compiler.CompileSession.generate(CompileSession.java:161)
at org.jetbrains.jet.compiler.CompileEnvironment.compileModule(CompileEnvironment.java:156)
... 89 more
even for the following code:
package hhh.csp
import org.apache.log4j.Logger
import org.apache.log4j.PropertyConfigurator
import org.junit.*
import org.junit.rules.ExpectedException
import junit.framework.TestCase
import junit.framework.TestSuite
public class IntervalTest(name :String) : TestCase(name) {
fun testIntervalPlus() {
val values : Array = Array(10000,{Interval.zero()});
var v:Interval = Interval.zero();
for( i in values ) i.u = 1.0;
for ( i in values) v = v+i;
println(v);
}
}
The problem with “compilation speed” is actually an IDE bug causing exceptions from the compiler to be processed very slowly. This bug is already fixed.
The exception you are getting also seems to be fixed. At least, this code compiles and runs OK for me: https://gist.github.com/2569478
Please, update your Koltin plugin to a nightly build:
1. Uninstall the plugin
2. Follow the nightly build instructions from here: http://confluence.jetbrains.net/display/Kotlin/Getting+Started