javac源和目标选项的用法 [英] javac source and target options usage

查看:105
本文介绍了javac源和目标选项的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们使用javac选项时:

-源 -target

编译器如何知道要产生的代码?

When we use javac option:
-source and -target
how does the compiler "knows" the code to produce ?

我的意思是任何编译器如何知道以前的
java版本的规范,或者我必须做一些设置才能为其提供
有关它们的一些信息?

I mean how does any compiler knows the specification of any previous java release or I have to do some setting in order to provide it with some information about them ?

推荐答案

javac 程序知道如何处理这些参数,而无需您提供任何其他信息。请注意,这里有一个陷阱:这些选项与源语法以及类文件的形式和内容有关,但是它们考虑到Java标准库。结果,尽管源Java版本或目标Java版本已设置为较早版本,它们仍将是编译依赖标准Java类(例如Java 7)中新方法的代码的理想内容。 原则上该结果可以在较早的Java版本上运行,但是在实践中,至少部分需要向后移植较晚的标准库。

The javac program knows how to handle these arguments without you providing any extra information. Do note that there is a bit of a trap here, however: these options relate to the source syntax and the class file form and content, but they do not take into account the Java standard library. As a result, they will be perfectly content to compile your code that relies on standard library classes or methods that are new in (say) Java 7, despite the source or target Java version being set to something earlier. In principle the result could run on that earlier Java version, but in practice that would require the later standard library to be backported, at least in part.

如果要为Java的特定最低版本开发 ,则应使用该版本的进行开发。如果您或其他人以后想使用以下方式重建源,则-源-目标选项选项会起作用。以后的 javac ,而不会降低与早期目标Java的运行时兼容性。

If you are developing for a particular minimum version of Java, you should develop using that version. The -source and -target options options come into play if you or someone else later wants to rebuild the source using a later javac, without dropping runtime compatibility with the earlier target Java.

这篇关于javac源和目标选项的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆