Can Java 8 Source Code Run on Java 7 JVM?
With the introduction of Java 8, significant language advancements, such as lambda expressions, have emerged. It's natural to wonder if these changes have altered the compiled bytecode to such an extent that it cannot execute on a Java 7 virtual machine without employing retrotranslators.
Answer:
Contrary to expectations, using Java 8 language features in your source code mandates targeting a Java 8 JVM. A recent experiment with the new Java 8 release, compiling with the flags -target 1.7 and -source 1.8, resulted in the following error:
$ javac Test -source 1.8 -target 1.7 javac: source release 1.8 requires target release 1.8
Hence, Java 8 source code cannot be directly compiled to run on a Java 7 JVM without modifications.
The above is the detailed content of Can Java 8 Source Code Run on a Java 7 JVM?. For more information, please follow other related articles on the PHP Chinese website!