简体   繁体   中英

Is the JDK required for Kotlin?

I have not used Android for a long time but now I find a new term, Kotlin, so my doubt is, JDK is required for Kotlin?

If Kotlin will replace to Java, so the JDK it is not necessary because according to me JDK is for develop on Java, is correct?

If it is correct then I have other doubt (this already it's old) why JDK is used for Android if this already include an Android SDK?

PD I am going crazy, I need a single explanation.

Yes, the JDK is required for Kotlin development on the JVM.

Historically, Kotlin worked with JDK 1.6+ targets. Starting with Kotlin 1.5 , Kotlin needs a JDK with version 1.8 (ie Java 8) or higher.

As already mentioned, Kotlin JVM requires the JVM to work. Kotlin compiles to JVM bytecode, which means it has the same requirements as Java (runtime and development kit). This is also why Kotlin has Java interop. Additionally, this is the one you're most likely to find yourself using with Android.

However, there is Kotlin Native . The SDK itself is slightly different from Kotlin JVM, and it's still a WIP, but it compiles without the need for JVM. Specifically, it compiles to a native target using LLVM. This version of Kotlin supports C interop.

Kotlin Native also opens the door for Kotlin Multiplatform , which compiles to whatever you want (mobile targets, desktop targets, and it packs it all into one, and includes interop with the native programming language). NOTE: I'm not sure what Kotlin Native with Multiplatform compiles to. Some demo projects use Kotlin JVM in the Android module, which suggests it doesn't use NDK-style native code. Multiplatforms, like Native, is experimental. I also haven't touched Multiplatform much, but it appears to be using a combination of declared functions and platform-declared functions. I'm not sure how interop works here (in terms of languages - not module interop).

Multiplatform doesn't require Native though, but it enables significantly more platforms. If you're using a cross-platform Java library (for an instance LibGDX), or otherwise build on modules with a core and platforms, you can use Multiplatform here too. However, note that this likely requires the JDK, although it does depend on your project.

In addition to these, there's also Kotlin.JS , which as the name suggests, compiles to JavaScript. Unlike Kotlin JVM, it naturally doesn't require the JVM. However, it instead requires the JavaScript-related APIs. And as you'd expect, Kotlin.JS supports JavaScript interop.

TL;DR:

The JDK isn't always required. Kotlin Native and Kotlin JS do not require the JDK, because the targets they compile to isn't on the JVM.

Yes! Kotlin 1.1.2 (and above) require JDK.

Also, very importantly, Kotlin wasn't supported so as to "replace" Java . This is another very common erroneous notion. Kotlin was merely added to the list of languages supported for writing Android apps.

You can check out the link below to get a feel of the language's history: https://en.wikipedia.org/wiki/Kotlin_(programming_language)

Kotlin compiles to jvm bytecode. It NEEDS a jvm. It can be used in place of Java the language

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