简体   繁体   中英

Kotlin Multi platform can you use Java or only Kotlin?

For Kotlin Multi-Platform, can you only use Kotlin or Java as well, to create cross-platform code? https://kotlinlang.org/docs/multiplatform.html

There is no mention of Java usage in https://kotlinlang.org/docs/native-overview.html#interoperability hence I doubt java is allowed to compiled into this native approach.

If java cannot be used that means all the Java libraries that exist cannot be used with this either (unless they are forked and migrated to Kotlin).

You are correct. Kotlin Multiplatform regards Java (and the JVM, by extension) as a compile target. That means that anything in the java.* and javax.* namespaces (as opposed to those in the kotlin.* and kotlinx.* namespaces, which are explicitly wrapped on the Kotlin side) cannot be used when targeting platforms other than the JVM.

It's a change in paradigm. When Kotlin first came out, it was intended as "Java but better", or "Java but safer". Interoperability with Java was at the forefront. And while Kotlin still supports tight integration with Java, it's a language in its own right, and Kotlin Multiplatform aims to see Kotlin able to evolve independently of Java, at least on platforms that aren't the JVM.

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