Eclipse:Java:源兼容性与编译器符合性级别 [英] Eclipse: Java : Source compatibility vs Compiler Compliance level

查看:397
本文介绍了Eclipse:Java:源兼容性与编译器符合性级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在eclipse中的源兼容性和编译器符合性级别之间有什么区别。

What is the difference between Source compatibility vs Compiler Compliance level in eclipse.

当我将我的编译器符合性级别设置为1.5时,我得到必须重写一个超类方法错误,由于使用@Override,但是@Override在1.5中添加。

When I set my Compiler Compliance level to 1.5, I get the "must override a superclass method" error due to the usage of @Override but @Override was added in 1.5.

为了解决这个问题,我将编译器符合级别更改为1.6,然后我不会得到上面的错误。请注意,我仍然有1.5套源兼容性。

To fix this issue i changed the compiler compliance level to 1.6 then I don't get above error. Please note I still have 1.5 set for Source Compatibility.

我喜欢知道两者之间的区别是什么,在什么情况下(或方案),我们需要使用上面

I liked to know what is the difference between the two and in what situation (or scenario) we need to use above settings in eclipse.

感谢

推荐答案

Source compatibility:

此设置应用于选择用户打算使用语言功能的Java版本。例如:将其设置为1.7意味着用户可以使用开关中的字符串,菱形结构等,但将其设置为1.6将意味着用户不能使用这种仅1.7的语言功能。
对于JDT编译器本身,我们使用1.4的合规性。是的,相当老式的你会说,但这是一个有意识的选择,使人们能够使用JDT编译器,即使他们没有安装在其机器上的Java版本高于1.4。

This setting should be used to select upto which java version the user intends to use the language features. Eg.: setting it to 1.7 means that the user can use strings in switch, the diamond construct, etc. but setting it to 1.6 will mean that the user can not use such 1.7-only language features. For the JDT compiler itself, we use a compliance of 1.4. Yes, quite old-fashioned you'd say, but this was a conscious choice to enable people to use the JDT compiler even if they dont have a version of java higher than 1.4 installed on their machines. You can also chose a source setting for your project on such considerations.

编译器符合性级别

此设置是一种开关,使JDT编译器符合某个Oracle javac版本。这是因为并非所有在Oracle javac编译器中修复的错误都被反向运行到早期版本。因此,每个javac版本之间有许多区别。有些情况下,只有一个javac版本与其他版本不同,前后不同。因此,我们为用户提供了合规性设置,以复制JDT编译器中行为的差异。这是为了使那些使用ECJ编译并随javac一起发送的人看到一致的错误(或缺少这些错误)。

This setting is a kind of a switch to make the JDT compiler "compliant" to a certain Oracle javac version. This is because not all bugs fixed in the Oracle javac compiler get backported to earlier releases. So, there are many differences between each javac version. There are even cases when only one javac version differs from the others, before and after it. So, we provided the compliance setting for users to replicate that difference in behaviour in the JDT compiler. This is to enable people who compile with ECJ and ship with javac or vice-versa, to see consistent errors (or the lack thereof).

参考

这篇关于Eclipse:Java:源兼容性与编译器符合性级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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