不完全是。以下是
proposal的链接:
We defined a new command-line option, --release, which automatically configures the compiler to produce class files that will link against an implementation of the given platform version. For the platforms predefined in javac, --release N is equivalent to -source N -target N -bootclasspath . (emphasis mine)
所以不,它不等于-source N -target N。添加的原因在“动机”部分中说明:
javac provides two command line options, -source and -target, which can be used to select the version of the Java language accepted by the compiler and the version of the class files it produces, respectively. By default, however, javac compiles against the most-recent version of the platform APIs. The compiled program can therefore accidentally use APIs only available in the current version of the platform. Such programs cannot run on older versions of the platform, regardless of the values passed to the -source and `-target. options. This is a long-term usability pain point, since users expect that by using these options they’ll get class files that can run on the specified platform version.
简而言之,指定源代码和目标选项不足以进行交叉编译。由于默认情况下,javac针对最新的平台API进行编译,因此无法保证在较旧版本上运行。您还需要指定与旧版本对应的-bootclasspath选项,以便正确交叉编译。这将包括正确的API版本来编译,并允许在旧版本上执行。由于它经常被遗忘,所以决定添加一个命令行选项,它完成所有必要的事情以正确的交叉编译。
进一步阅读in the mailing list和Oracle Docs.原始错误是here提交的。请注意,自从该选项的集成之后,JDK版本已经捆绑了老版本的平台API的描述,在“风险和假设”一节中提到。这意味着您不需要安装在机器上的旧版本来交叉编译才能正常工作。