在使用Java编译器(javac
)时,我们可以指定两种兼容性。一种是使用-source
,另一种是使用-target
。这两者有什么区别?
例如 -source 1.5
和 -target 1.6
?
另外,是否存在我们使用不同的源和目标兼容级别的情况?
最佳答案
来自 javac docs :
-source Specifies the version of source code accepted.
-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 及更高版本的类文件。
为什么你会这样做是另一回事。
关于java - -source 和 -target 兼容性有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10663450/