Kotlin M2 Candidate

It’s been seven weeks since Kotlin M1 release, and I’m happy to invite you to try out a candidate build of Kotlin M2! This post gives an overview of the upcoming milestone release along with come usage instructions.

Thank you, M1!

Our M1 build did a pretty good job: got about 800 downloads, and brought extensive feedback in our forum and issue tracker.

Seems like you have had some fun with it, and we are aiming at even more fun :)

What’s new

Little Things

As usual, it’s been a lot of bugs fixed. I’d like to point out that we are working on the IDE performance. It has been somewhat improved in M2, and will get to its real speed by the next milestone.

Language Features

Kotlin now respects visibility modifiers. We have four of them:

  • privateprotectedpublic — as usual,
  • internal — visible inside a module (that is more than a package).

You can now pass an array of values to a vararg-function:

fun printAll(vararg a : String) {
    for (item in a) println(item)
}

fun main(args: Array<String>) {
    printAll("one", "two")
    printAll(*args)
}

The spread operator “converts” an array into a vararg-list. Unlike Java, this does not present any ugly corner-cases.

There will a few more nice things shortly.

JavaScript Support in the IDE

While you can still play with Kotlin directly in your browser with Kotlin Web Demo, there’s now a real IDE for Kotlin compiled to JavaScript.

When you install the M2 Candidate build of the IntelliJ IDEA plugin, follow these instructions to try out some Kotlin-to-JS compilation:

  • Check out kotlin-js-hello project from github
  • Open it as an IntelliJ IDEA project
  • Set it up as a Kotlin-JS project
  • Select your favorite browser and run. The result will open in the browser.
  • Have fun editing the JavaScript file as you like and re-running…

Currently, the API documentation is only being prepared. Meanwhile, you can study Kotlin’s JS APIs here.

Android

After fixing some bugs and finding out a lot of interesting stuff (special thanks to Aleksandro Eterverda), we are ready to run Kotlin on Android!

Some other Kotlin programs running on Android:

How to Install the Candidate Build

As usual, your feedback is very welcome. Have a nice Kotlin!


 

Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.

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.

19 Responses to Kotlin M2 Candidate

  1. Guangyu says:

    Congratulations! Let’s kotlin…
    Now is it time to use it in product develop enviroments?

  2. Otto Christian says:

    Amazing work! Thanks for all the hard work to all the Kotlin team. Javascript and Android improvements in this milestone are big steps.

    I tried running the Android sample, which worked, but still have not succeeded in using the kotlinAndroidLib (when I add an activity with AndroidManifest and layout.xml to this project I get [INSTALL_FAILED_DEXOPT], and also when I tried it in another project, I got unresolved reference even though I included the necessary kt files. Anyway, I will ask about this in the forum.

    Therefore the only feedback I have is perhaps to create troubleshooting tools for developers. I encountered situations in the past where I think I have everything configured correctly, yet I get “unresolved reference” or other errors that are hard to understand and troubleshoot.

    As a side note, but his is one general frustration with very advanced environments like IntelliJ. Because it is a very complex tool, sometimes there are many things that need to be tweaked in various areas (project settings/system settings). On the other hand, command-line tools tend to be simpler to troubleshoot. Can something be created to help us troubleshoot things (a tool or or even a web page with troubleshooting steps)? I feel this may sometimes be overlooked by the IntelliJ development team because they are intimately familiar with IntelliJ so the solutions may seem obvious to them, but for the average user it is not obvious.

    • Thanks for the kind words, Otto!

      Please, attach the project that didn’t work to the forum post.

      We’ll see what can be done about troubleshooting, but so far StackOverflow+Google seems to be the best way invented. It’s too early for it to work for Kotlin, though.

    • Vladimir says:

      Hi. Sorry for the library. I’ve found the problem, please use latest code, I’ve fixed the issue with INSTALL_FAILED_DEXOPT. It was because of similar overloading functions.

      Please, let me know if you have any problems with kotlinAndroidLib. Thank you.

      • Otto Christian says:

        Vladimir, I finally got pulled the latest and tried it again, and it works great. Excellent work, it makes Android code very concise and easy to read! Thank you!

        • Vladimir says:

          No problem. I will try to investigate what else I can wrap and also waiting for lazy values, so we can just write findView and define views out of onCreate method ;)

  3. Henrik S Törnblom says:

    Keep up the good work.

    For the last week I have been experimenting with programming a MongoDb client with Kotlin. Having fun.

  4. Igor Karpov says:

    I’d like to suggest a feature for Kotlin.
    In a nutshell, it would be nice to have a way to express complex object literals in Kotlin, and it could be a language of its own.
    Just like JSON is a subset of javascript, there could be a really small subset of Kotlin. It could be used in configuration files, message payloads, etc. But more usable than JSON, and with organic integration with Kotlin.
    You can take a look at my project on github: https://github.com/semicontinuity/lepton – tried to do something like that few years ago, for java.

  5. Igor Karpov says:

    Not really..
    What I mean is something like ‘Rich JSON’ – a companion language for Kotlin. No ‘fun’ or ‘class’, just a data structure. See an example: https://github.com/semicontinuity/lepton/blob/master/README.md

    I’ve written some builders in grooovy, and disliked the fact that quite a lot of glue code has to be written.
    In Kotlin, it looks the same…
    A lot of code just to be able to use builders syntax. And that code has no value by itself…
    For Instance, I like JAXB to convert JSON or XML to java objects. Not that it’s perfect, but no glue code… And to write by hand the code to support builders – for me it’s a step back.

  6. Robert says:

    Inline functions have different semantics than control structures, but the same syntax. For example:
    while (x < 10) { x++ }
    would have a different meaning if while() was an inline function.

    I don’t mean this to bash the concept… I really like the potential of inline functions to cut down boilerplate code. But, I wonder if there’s a more powerful form of metaprogramming lurking in the concept there somewhere.

    • “while” is a keyword, no function can be called “while”, same for other built-in control structures.
      The only ways in which inline functions are more powerful than normal functions are
      1. non-local returns and jumps.
      2. dataflow analysis can look into their bodies.
      This is not a huge difference. The main point of inlining is performance.

  7. David M says:

    Am wondering what the best way to write this to JSON is:

    object {
    val name = “Fred”
    val arr = array (1,0)
    }

    Jackson seems unable to handle this.
    However, given that Kotlin produces Javascript, there ought to be a built-in way of doing this, no?

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> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>