简体   繁体   English

Kotlin编译器是否编译java文件?

[英]Does the Kotlin compiler compile java files?

I have a project with both .java and .kt files. 我有一个包含.java和.kt文件的项目。 Does the Kotlin compiler compiles both .java and .kt files or does it only compile my .kt files? Kotlin编译器是否编译.java和.kt文件,还是只编译我的.kt文件?

No, kotlinc compiles only Kotlin files ( .kt ). 不, kotlinc只编译Kotlin文件( .kt )。 A mixed-language project requires combining both kotlinc and javac . 混合语言项目需要结合kotlincjavac If the references flow only one way, eg, if Java code references Kotlin code and not the other way around, then the compilation order is pretty easy to figure out. 如果引用仅以一种方式流动,例如,如果Java代码引用Kotlin代码而不是相反,那么编译顺序很容易理解。 In that situation, you would compile the Kotlin code first, then include the output in the classpath to javac when compiling the Java code. 在这种情况下,您将首先编译Kotlin代码,然后在编译Java代码时将类路径中的输出包含到javac

If the two are more intertwined, it becomes a little more complicated. 如果两者交织得更紧密,那就变得有点复杂了。 Looking at this thread , it appears you'll need to run kotlinc first, passing in any referenced Java source files (as the .class files won't be available yet). 看看这个线程 ,你似乎需要首先运行kotlinc ,传入任何引用的Java源文件(因为.class文件尚不可用)。 The class files built by kotlinc can then be included in the classpath when you compile your Java files. 然后,在编译Java文件时, kotlinc构建的类文件可以包含在类路径中。

它本身并没有,但运行Kotlin编译器(根据其文档https://github.com/JetBrains/kotlin )的要求之一是JDK,所以如果你有Kotlin你也有javac

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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