title | date | author | tags | keywords | categories | reward | reward_title | reward_wechat | reward_alipay | source_url | translator | translator_url |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Kotlin M5.2: IntelliJ IDEA 12.1 and Gradle |
2013-04-04 08:00:00 -0700 |
Andrey Breslav |
官方动态 |
false |
Have a nice Kotlin! |
Another update of Kotlin comes out today. Welcome Kotlin M5.2.
Koltin M5.2 supports (in fact, requires) the recently released IntelliJ IDEA 12.1 . The Kotlin IDE improvements include:
- Kotlin classes in the Class Hierarchy view. Just hit Ctrl+H on a class name to see its descendants and/or parents.
- Folding for imports (you don’t have to scroll through imports to get to your code any more).
- New UI for Kotlin library configuration: you can now control library names and location, and kotlin-runtime.jar is not copied to your project by default. It just works.
- Support for JavaScript-targeted modules is significantly improved.
- Optimizing imports on the fly: IDE Settings -> Editor -> Auto Import -> Optimize imports on the fly.
- New quick fixes: place the cursor on an error, and hit Alt+Enter.
{% raw %}
{% endraw %}When using Java libraries, you can now create an instance of a SAM interface (one with a Single Abstract Method) by calling its name and passing a function literal. For example:
{% raw %}
{% endraw %}SwingUtilities.invokeLater(Runnable { doItNow() })
{% raw %}
{% endraw %}This works only for Java classes. In fact, it is not a part of the language, but a feature of how Java classes are loaded into Kotlin: we define a synthesized function
{% raw %}
{% endraw %}fun Runnable(body: () -> Unit) = object : Runnable {
override fun run() {
body()
}
<span style="color: #222222;font-family: 'Courier 10 Pitch', Courier, monospace;line-height: 21px">}</span>
{% raw %}
{% endraw %}So whenever you import Runnable, the function is there too, and you can use it. This is the first chunk of SAM-conversion support for Java. Real SAM conversions will come soon, and you’ll be able to say simply
{% raw %}
{% endraw %}SwingUtilities.invokeLater { doItNow(); }
{% raw %}
{% endraw %}Starting with M5.2, in addition to the long-available Maven plugin, there’s a Gradle plugin for Kotlin from JetBrains. Here’s an example for building a Kotlin module with Gradle:
{% raw %}
{% endraw %}buildscript {
repositories {
mavenCentral()
maven {
url 'http://repository.jetbrains.com/all'
}
}
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.1-SNAPSHOT'
}
}
apply plugin: "kotlin"
repositories {
mavenCentral()
maven {
url 'http://repository.jetbrains.com/all'
}
}
dependencies {
compile 'org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT'
}
{% raw %}
{% endraw %}More examples & docs can be found here .
Don’t forget that you now have KAnnotator at your service. Have a nice Kotlin!