可以编译 Java 8 代码以在 Java 7 JVM 上运行吗? [英] Can Java 8 code be compiled to run on Java 7 JVM?

查看:32
本文介绍了可以编译 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

这篇关于可以编译 Java 8 代码以在 Java 7 JVM 上运行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆