简体   繁体   中英

Kotlin with JDK 10

Recently I updated my JDK to JDK 10, and now I get configuration issue with Kotlin and I can't run my code. is this because of JDK 10 or it's because something else?

the hint I get from InteliJ while creating a Kotlin Project:

Configure Kotlin
        Added /Applications/IntelliJ IDEA CE.app/Contents/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-jdk7.jar to library configuration
        Added /Applications/IntelliJ IDEA CE.app/Contents/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-jdk7-sources.jar to library configuration
        Added /Applications/IntelliJ IDEA CE.app/Contents/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-jdk8.jar to library configuration
        Added /Applications/IntelliJ IDEA CE.app/Contents/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-jdk8-sources.jar to library configuration

At the time of writing (Sept. 2018) Kotlin's compiler does not support producing Java 9+ bytecode by default.

The argument -jvm-target 9 ( see KT-21959 ) should make the Kotlin compiler generate bytecode of version 53.

Since Java 10 is bytecode version 54 ( reference ) - I'm not sure how this will work.

Still:

  • You can compile to the JVM 8 bytecode which can be executed on JVM 9+ normally.

  • If you want to define modules (or use jlink that requires the entire program is modularized) you can write module-info.java files in Java today, and place in the same source root as Kotlin files.

    • The Kotlin compiler will correctly limit the accessibility of declarations in non-exported packages in dependent modules.
    • Currently, there are no plans to support module definitions in Kotlin.

Other than that, most Java 9-11 language features (var, REPL, streams improvements, etc.) - already exist in Kotlin for a while, so the main immediate benefit of using Java 9-11 are using the JVM for the optimizations, or the module system / jlink (which you can use as descrbied above)

1.3.30版本开始,Kotlin现在支持JVM字节码目标9、10、11、12。( KT- 26240 - LppEdd提到的票-已包括在内。)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM