-source和-target兼容性有什么区别? [英] what's the difference between -source and -target compatibility?

查看:702
本文介绍了-source和-target兼容性有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用Java编译器( javac )时,我们可以指定两种兼容性。一个是使用 -source ,另一个是使用 -target 。这两者之间有什么区别?

When using the Java compiler (javac), we can specify two kinds of compatibility. One is using -source and the other is using -target. What is the difference between these two?

例如, -source 1.5 -target 1.6

此外,是否有任何情况下我们使用不同的来源和目标兼容性级别?

Also, is there any case where we use a different source and target compatibility level?

推荐答案

javac文档


-source 指定接受的源代码版本。

-source Specifies the version of source code accepted.

-target 生成以指定版本的VM为目标的类文件。

-target Generate class files that target a specified version of the VM. Class files will run on the specified target and on later versions, but not on earlier versions of the VM.

在您的示例中:

-source 1.5 and -target 1.6

这将用于确保源代码与JDK 1.5兼容,但应生成在JDK 1.6及更高版本上使用的类文件。

This would be used to make sure that the source code is compatible with JDK 1.5, but should generate class files for use on JDK 1.6 and later.

这篇关于-source和-target兼容性有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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