Sunday, 15 May 2011

Why does Eclipse let me compile some Java 7 language features into Java 6 class files? -



Why does Eclipse let me compile some Java 7 language features into Java 6 class files? -

i have found in eclipse (using eclipse compiler) can utilize java 7 language features still create java 6 class files. in below image, can see 2 java 7 language features compiled java 6 class file. however, other java 7 features, commented out, not compile.

my assumption eclipse determining java 7 language features compatible java 6 jvm , not. example, generic type jcombobox compilation (and not runtime) feature, can imagine how compatible. switch string feature though think might create differences in byte code , rely on new jvm features, wrong...

my questions:

is eclipse smart plenty know java 7 language features capable of beingness compiled java 6 class files , not?

the illustration below not 1.6 source compatible, why setting "source compatibility" 1.6 not cause error?

this "trick" appears allow me utilize @ to the lowest degree java 7 language features , still create java 6 class files. using javac source 1.7 , target 1.6 fail, why work? ecilpse compiler have feature javac not?

for sake of comparing here result when switch java 6 compiler, expected.

i think 2 things happening:

i suspect first line (with generic jcombobox) works because java 1.7 rt.jar linked instead of java 1.6 rt.jar (i have project setup javase-1.6, , in case, first line not compile first combination of settings). class library issue, not language version issue. (you can lots of issues javac if compile java app against newer rt.jar when run it).

the sec line represents bug in eclipse compiler. while of java 7 new language features can implemented purely in compiler (which android since late 2013), doing not source-compatible java 6.

so, in short, have found @ to the lowest degree 1 bug in (probably) unusual eclipse configuration. take care , not rely on it.

java eclipse ecj

No comments:

Post a Comment