Why can't the Java compiler compile Java 1.5 source code (for example, for each loop) into Java 1.4 bytecode?
I know that you can provide the -target 1.4 switch, which tells the compiler about the release of 1.4 compatible bytecode, but that requires -source 1.4 .
$ javac -target 1.4 -source 1.5 Test.java javac: source release 1.5 requires target release 1.5
Now I take a course in building the compiler, and as I understand it, compilers in any case convert the source code to an intermediate representation. Why can't such an intermediate representation be output as 1.4 compatible bytecode? This sounds like a pretty simple task, since for each cycle varargs, etc. Mostly syntactic sugar!
(Note that I see that the API classes introduced in Java 1.5 cannot explicitly be mentioned when running on the 1.4 JVM. I'm still interested in the situation when you stick with the 1.4 API.)
source share