Home > Java > javaTutorial > body text

Can Java 8 Source Code Run on a Java 7 JVM?

Mary-Kate Olsen
Release: 2024-11-07 17:47:03
Original
473 people have browsed it

Can Java 8 Source Code Run on a Java 7 JVM?

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template