如何在Kotlin Native中导入Java包 [英] How to import Java packages in Kotlin Native
问题描述
我正尝试导入Java包,以用于Kotlin本机,如下所示;
I'm trying to import Java package for use in Kotlin native as below;
/* main.kt */
import java.util.*
fun main(args: Array<String>) {
print("Simple program")
}
并使用以下命令进行编译
and compile it with the below command
kotlinc main.kt -o main
我收到了错误消息
main.kt:2:8: error: unresolved reference: java
import java.util.*
很显然,我需要向kotlinc显示在哪里可以找到java.util,如何在不使用命令行的情况下实现这一点?我在Windows 10 64位上使用Kotlin本机0.3.
obviously I need to show kotlinc where to find java.util, how can I achieve this without using the command line? I'm on Windows 10 64 bit using Kotlin native 0.3.
推荐答案
您将无法访问Kotlin Native中的Java软件包.该项目的全部重点是在没有VM的情况下运行Kotlin代码,因此您无需使用Java虚拟机(或库).但是,您可以改用本机C库.您可以在此处找到相关信息.
You won't have access to Java packages in Kotlin Native. The whole point of this project is to run Kotlin code without a VM, so you don't have the Java Virtual Machine (or libraries) to use. You can, however, use native C libraries instead. You can find information about how this works here.
从公告发布 Kotlin/Native的第一个预览:
From the announcement post of the first preview of Kotlin/Native:
请注意,我们不打算使任意Kotlin/JVM程序可在Kotlin/Native或Kotlin/JS上运行.这将等效于实现另一个JVM,这既工作量大,运行时也有很多限制.我们正在采取另一种方式:为所有平台提供一种通用语言,同时通过与平台代码的无缝互操作性来创建通用库.
Note that we do not intend to make arbitrary Kotlin/JVM programs runnable on Kotlin/Native or Kotlin/JS. It would be equivalent to implementing another JVM, which is both a lot of work and a lot of limitations for the runtime. We are going another way: providing a common language for all platforms while enabling creation of common libraries through seamless interoperability with platform code.
这篇关于如何在Kotlin Native中导入Java包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!