可以编译Java 8代码以在Java 7 JVM上运行吗?

问题描述:

Java 8引入了重要的新语言功能,例如lambda表达式。

Java 8 introduces important new language features such as lambda expressions.

语言中的这些更改是否伴随着编译后的字节码中的这些重大更改会阻止它在不使用某些反向转换器的情况下在Java 7虚拟机上运行?

Are these changes in the language accompanied by such significant changes in the compiled bytecode that would prevent it from being run on a Java 7 virtual machine without using some retrotranslator?

不,使用源代码中的1.8功能需要您目标是1.8 VM。我刚刚尝试了新的Java 8版本并尝试使用 -target 1.7 -source 1.8 进行编译,编译器拒绝:

No, using 1.8 features in your source code requires you to target a 1.8 VM. I just tried the new Java 8 release and tried compiling with -target 1.7 -source 1.8, and the compiler refuses:

$ javac Test -source 1.8 -target 1.7
javac: source release 1.8 requires target release 1.8