title: Why can't javac compile Java 1.5 code to run on Java 1.4 JVMs?
body: <p>Why can't the Java compiler compile Java 1.5 source code (with for-each loops for instance) to Java 1.4 bytecode?</p>
  
  <p>I know that you can provide a <code>-target 1.4</code> switch, which tells the compiler to produce 1.4 compliant bytecode, but this requires <code>-source 1.4</code> as well.</p>
  
  <pre><code>$ javac -target 1.4 -source 1.5 Test.java
  javac: source release 1.5 requires target release 1.5
  </code></pre>
  
  <p>I'm taking a course in compiler construction now, and as I understand it, compilers transform the source code into an intermediate representation anyway. Why can't such intermediate representation be output as 1.4 compliant bytecode? It sounds like an easy enough task, since, for each loops, varargs etc are basically just syntactic sugar!</p>
  
  <p>(Note that I can see that API classes introduced in Java 1.5 obviously can't be referred to when executing on a 1.4 JVM. I'm still interested in the situation in which you stick to the 1.4 API.)</p>