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

IntelliJ 2018.1中‘Use --release option’选项的作用是什么?

What Does the "Use '--release' option for cross-compilation (Java 9 and later)" Checkbox Do in IntelliJ 2018.1?

Hey there! Sorry the help link threw a 404 on you—let me walk you through exactly what this option does, and why it’s useful.

Core Purpose

This checkbox tells IntelliJ to use Java’s --release command-line argument instead of the older -source and -target flags when cross-compiling code for Java 9 or later versions.

Why --release is Better Than -source/-target

Before Java 9, developers relied on -source (to define the minimum Java version their code is written for) and -target (to set the bytecode version generated) for cross-compiling. But this approach had a critical gap: it only validated syntax and bytecode compatibility, not API availability.

For example, if you compiled code with JDK 17 using -source 11 -target 11, you might accidentally use a method added in JDK 17 that doesn’t exist in JDK 11. The compiler would let this pass, but when you tried to run the code on a JDK 11 VM, you’d hit a NoSuchMethodError or similar runtime failure.

The --release flag fixes this: it not only sets the source and target versions, but also restricts your code to only use APIs that were available in the specified Java release. If you try to use a newer API, the compiler will throw an error during compilation—saving you from frustrating runtime bugs.

When to Use This Option

You’ll want to check this box if:

  • You’re using a newer JDK (9+) to compile code that needs to run on an older Java version
  • You want to enforce strict compatibility with your target Java runtime, avoiding accidental use of unsupported APIs

Quick Example

If you’re working with JDK 16 and want your code to run on JDK 11, enabling this option and setting your target release to 11 will flag any JDK 12+ APIs you try to use as compilation errors.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 08:40:19