It’s been a little more than a year since the first commit was pushed to our source control, and we are happy to announce the first public preview of Kotlin.
This preview works as follows:
- You go to http://kotlin-demo.jetbrains.com and it loads a code editor in your browser:

- You check out examples, modify them or even solve our sample toy-problems;
- You run your code on a JVM running on our server, so that you can use familiar JDK classes;
- Or, alternatively, you compile you code to JavaScript and run it in your browser:

Note that the JavaScript back-end is a pre-alpha version, so it may refuse to compile some of your programs.
Experimental features
By default, you get error highlighting only when you run your program. But you can try out some of the features we are experimenting with and turn on “as-you-type” error highlighting:

If you choose “Server”, the editor starts talking to a type checker service hosted on our server. If you choose “Client”, a type checker is loaded as a (so far rather big) Applet which runs on your machine.
Both “Server” and “Client” options give you code completion as well:

Please, note that these features are experimental and feel free to report any problems to us.
Coming soon
This demo will be developed further for you to have more fun. Among other things we plan to add the following:
- Standard Library of extension functions that make using JDK collections and other common APIs more pleasant (things like map()/filter() and so on);
- Code Challenge: currently we offer a few sample problems in the form of code snippets containing test data. This will be extended to contest-like automated testing system.
- More Examples: There’s always some more to show off
finally
solved the pairless problem.
for (i in a) {
if (lonely.contains(i)) {
lonely.remove(i)
} else {
lonely.add(i)
}
}
val it = lonely.iterator()
if (it != null) {
return it.next()
}
return -1;
is it possible to switch off the “this is a java method, it might return null! you need to check it!”-rule? if i had a mixed java/kotlin project, the kotlin code would be scattered with either if ( != null) or “?” otherwise….
and about the extension functions to make java collections more pleasant to use – this is your enemy:
def findPairless(t: Seq[Int]) = t.filterNot(e => t.count(_ == e) % 2 == 0).distinct
On the nullability of Java types: we are working on it.
From the scala-user mailing list:
HamsterofDeath Jan 10 09:25PM +0100
You shouldn’t trust to this man.
We are always glad when other projects learn from us (as we learn from them all the time).
One correction: Kotlin has “destructuring” (we call it “decomposing”), although it is not finished yet.
Great answer. Humans’ evolution is more important, than one sole programming language or single library.
This is why you are project leader Andrey. All the best!
I still haven’t understood what the problem is.
It’s not like any of this stuff is secret.
Very nice! And very interesting language. Congratulations to Andrey and the gang
Great job!!!
Where sould we discuss possible bugs or differences beetween the «specifications» and the demo?
I think our bug tracker is currently the best place for it: http://youtrack.jetbrains.net/issues/KT
And there will be a forum soon
Could Kotlin pull a “Visual Basic” on the software community? This example may be the start of something. Well done guys!
I’ve seen the preview a few days ago. VERY impressive. The Web IDE itself is much better than some other ‘web IDEs’.
However, now that you are teasing us with preview – can you tell when the full stand-alone compiler will be available?
We are planning to open a public open source preview version of the compiler sometime before the end of March.
Take your time. The worst thing that might happen would be to go the same way some other languages went, and start releasing half-baked features, followed by the same basic feature in a little different form, again and again.
I really enjoyed the infix extensions functions:
fun String.log(){
System.out?.println(this);
}
fun String.format(p0 : String) : String{
return String.format(this, p0).toString();
}
fun main(args : Array) {
val e = "Too Awesome";
"Database error: %s".format(e).log();
"Database Access Required".log();
}
A few questions arise though:
1. How are infinite argument lists defined (ala printf). IDE suggests
p : ... : String, but that did not really work.2. If annotation support is in yet – how do you define them?
Varargs are defined as:
fun foo(vararg s : String) {
// s in an array here
}
Annotations are not supported yet, but the definitions will look like
annotation class persistent() {}
Usage:
persistent class Foo(…) {…}
This is a bug?
var s = null : String?
s = “a”
var s1 = “” // String – ?
if (s != null) {
s1 = s.toString() // return String?
s1 = s // Error “Type mismatch: inferred type is String? but String was expected”
val s2 = s
val s3 = s.toString()
}
This is a bug in diagnostics. The compiler should have told you that ‘s’ is a var and thus smart casts do not work for it. Only immutable values can be safely cast.
I filed an issue about it: http://youtrack.jetbrains.net/issue/KT-969
Thanks. It was a terrible code, but why there is no error here:
s1 = s.toString() // return String?smart cast?
No, we simply call Kotlin’s toString() that never returns null. If you say null.toString() you just get a string “null”.
Ups! of course – s?.toString()
But I have in mind this assignment:
s1(String type) = s?.toString()(String? type)
This wont compile:
var s1 : String = s?.toString()
This will:
var s1 : String = s.toString()
I understood.
wow, the web demo of Kotlin is impressive. Awesome!
Is Jetbrains planning to release full-blown web IDE? Would it be a separate product than IntelliJ? I wonder if perhaps eventually it will supersede and replace IntelliJ altogether?
Also, I notice that if I start using Kotlin I will have lots of “fun” all over my code. So I’d like to suggest that Jetbrains change the motto for the Kotlin IDE from “Develop with pleasure!” to “Develop with lots of fun!”
Currently this is only a demo. If we ever build a full-featured web-based IDE, it is unlikely to be developed up from this.
Are you monitoring the web demo for compiler crashes? (I managed to crash it yesterday and can’t see any related issues in the tracker).
Would you prefer any such issues to be reported via the issue tracker directly? Or should I just give you a chance to get to it?
We monitor crashes in the demo, but they need manual preprocessing to be added to the tracker, so this will take time. If you don’t mind filing an issue yourself, it won’t hurt
Anyone can summarily list what I’d possibly lose if I gave up on groovy for Kotlin – except embracing this silly name, Kotlin?
“Kotlin” is a code name.
Comparing to Groovy, you get static typing and better performance (no reflective calls), to begin with. If you don’t care about these things, you are probably happy with Groovy and don’t need Kotlin.
I had to use while loop in the Palindrome problem:
var i = 0
while(i < s.length) {
if (s.get(i) != s.get(s.length - 1 - i))
return false
i++
}
return true
The solution with for the classical C-style for loop is shorter by two lines of code:
for(int i = 0; i < s.length; i++) {
if (s.get(i) != s.get(s.length - 1 - i))
return false
}
return true
Are you going to implement this kind of loop from Kotlin?
You can use ranges:
for (i in 0..s.length-1) {
...
}
Documentation in :
“Strings are represented by the type String. Strings are immutable. … A string can be iterated over with a for loop:
for (c in str) { println(c) }”
In Web Demo:
——–
fun isPalindrome(s : String) : Boolean {
for (c in s)
{
}
return true
}
Error message: For-loop range must have an iterator() method
—–
Bug in Web demo or error in documentaion?
This is due to the temporary absence of the Standard Library in the Web Demo. We’ll fix it soon.