You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JVM编译Kotlin代码时是否使用Kotlinc?还是沿用Javac?

Kotlin代码的JVM编译流程详解

Awesome question—let’s unpack how Kotlin works with the JVM step by step, since it’s a common point of confusion when switching from Java.

1. 主流路径:直接编译为JVM字节码

When working on JVM-based Kotlin projects (the most common scenario), you’ll use the kotlinc compiler directly. Here’s what happens:

  • kotlinc takes your Kotlin source files (.kt) and compiles them straight into standard JVM bytecode (.class files)—the same format that Javac produces from Java code.
  • The JVM doesn’t need Javac at all here. It runs the Kotlin-generated bytecode exactly like it runs Java bytecode, since they’re fully compatible.
  • Tools like IntelliJ IDEA, Gradle, or Maven all use this flow by default when building Kotlin JVM projects.

2. 可选路径:先转Java代码,再编译

Kotlin does support converting its source code to equivalent Java code (via flags like kotlinc -Xemit-java or IDE tools), but this is a niche use case—mostly for debugging, understanding how Kotlin constructs map to Java, or integrating with legacy systems that only accept Java source.

  • If you take this route, the generated Java code would then need to be compiled with javac to produce bytecode. But this is not the standard way to build Kotlin applications for the JVM.

Key Takeaway

Kotlin is a first-class JVM language, and kotlinc is its dedicated compiler for the JVM platform. It produces bytecode that’s indistinguishable (in terms of JVM compatibility) from Javac’s output, which is why Kotlin and Java code can interoperate seamlessly on the JVM.

内容的提问来源于stack exchange,提问作者Iliasvw

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:58:05