Eclipse: Java : Source compatibility vs Compiler C

2019-08-09 08:22发布

问题:

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

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.

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.

Thanks

回答1:

Source compatibility:

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.

Compiler Compliance level:

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).

Reference