So I know Kotlin Native is obviously Native and Kotlin JVM isn't but is the code between Kotlin JVM and Kotlin Native: 1. Different Compiler and Different Code 2. Different Compiler and Similar Code 3. Different Compiler and Same Code 4. None of the above (please explain)

推荐答案

The Kotlin/JVM and Kotlin/Native compilers share the front-end (the part that performs code parsing, name resolution, type inference etc.), but the compiler back-ends that translate the internal program representation to the target code (the JVM bytecode and LLVM bitcode, respectively) are different.

The Kotlin language accepted by the two compilers is the same, but some of the features and checks are platform-specific. Also, the standard libraries for Kotlin/JVM and Kotlin/Native are sufficiently different, see the APIs available on each platform here: Kotlin Standard Library.

Another big difference is the memory model: Kotlin/JVM uses the Java memory model, while Kotlin/Native offers its own concurrency and memory model.

此外,可以在Kotlin/JVM和Kotlin/Native项目中使用的依赖项也不同.除了使用同一Kotlin目标建造的项目外:

  • Kotlin/JVM can also use any libraries built for the JVM (written in Java, Scala etc.)

  • Kotlin/Native还可以使用C interop tools与用C编写的本机库(或至少具有C头)进行互操作

  • Kotlin/JVM和Kotlin/Native都可以使用Kotlin多平台库.考虑到依赖项是一个多平台库,可以在Kotlin/JVM和Kotlin/Native之间完全重用使用它的代码.

Kotlin相关问答推荐

来自SnapshotFlow的单元测试StateFlow仅发出initialValue

Kotlin中的增广赋值语句中的难以理解的错误

Kotlin-stdlib中的模拟扩展函数

处理合成层次 struct 中的深层按钮以切换视图

为什么不';Kotlin是否在数据类构造函数中隐式分配null值可为null的字段?

为什么Kotlin有次构造函数和init块?

协程子作业(job)取消

按钮无法在 Android Studio 上打开新活动

如何规避 Kotlin 的泛型类型差异约束

如何将 `throw` 放置在辅助函数中但仍然具有空安全性?

Kotlin 插件之间的区别

T except one class

找不到引用的类 kotlin.internal.annotations.AvoidUninitializedObjectCopyingCheck

将 Kotlin 类属性设置器作为函数引用

`this@classname` 在 Kotlin 中是什么意思?

使用 Paging 3 时保存并保留 LazyColumn 滚动位置

如果我可以将 Flow 和 StateFlow 与生命周期范围 \ viewLifecycleOwner.lifecycleScope 一起使用,那么在 ViewModel 中使用 LiveData 有什么意义

spring.config.location 在 Spring Boot 2.0.0 M6 上不起作用

Android:Exoplayer - ExtractorMediaSource 已弃用

Kotlin 中的填充字符串