简体   繁体   English

是否可以编译较新的Java版本(9,10,11)以在较旧的平台(例如Java 8)上运行?

[英]Can newer Java version (9, 10, 11) be compiled to run on older platforms (e.g Java 8)?

Is it possible to develop using newer Java (eg 9, 10, 11 etc.) versions, and have that Java be compiled down to some older version - such as Java 8? 是否有可能使用较新的Java(例如9,10,11等)版本进行开发,并将Java编译为某些旧版本 - 例如Java 8?

We would like to use the new features of newer Java versions, but our code needs to run on a Java 8 platform. 我们希望使用较新Java版本的新功能,但我们的代码需要在Java 8平台上运行。

If it matters: we are building with Maven. 如果重要:我们正在与Maven一起建设。


Phrasing it in Javascript fashion: 用Javascript方式表达它:

Does there exist a Babel Polyfill equivalence for Java? 是否存在Java的Babel Polyfill等价?

Not necessarily. 不必要。 If you have code that uses packages/syntactical structures not defined in previous versions, the program will fail to run/compile. 如果您的代码使用以前版本中未定义的包/语法结构,则程序将无法运行/编译。

Think of it this way. 这样想吧。 Before Java 8, there were not lambda expressions. 在Java 8之前,没有lambda表达式。 So if you create a lambda expression in Java 8+ and then attempt to compile it in java 7, the compiler will be like: What is a lambda expression? 因此,如果您在Java 8+中创建一个lambda表达式然后尝试在java 7中编译它,编译器就会像:什么是lambda表达式?

In short no. 总之没有。 However, you can go the other way. 但是,你可以走另一条路。 Compile code written in a lower version using a higher version... for the most part. 在大多数情况下,使用更高版本编译以较低版本编写的代码。

No - you cannot use new features on an older JVM; 不 - 您不能在旧JVM上使用新功能; the bytecode is incompatible . 字节码是不兼容的

You can absolutely use the newer versions of Java to compile down to a lower version, with some caveats around modules. 您可以绝对使用较新版本的Java编译为较低版本,并对模块有一些警告。

If you need the new features of newer Java versions, then it's time to migrate to a new version; 如果您需要更新的Java版本的新功能,那么是时候迁移到新版本了; other than that, where you are will be fine until you require support from Oracle. 除此之外,在您需要Oracle支持之前,您将处于良好状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 较新的JRE版本可以运行用较旧的JDK版本编译的Java程序吗? - Can newer JRE versions run Java programs compiled with older JDK versions? 临时变量的效率(例如java) - Efficiency of temporary variables (e.g java) 如何为Java 11编译和运行我的Maven单元测试,同时为旧版Java 8编译我的代码 - How to compile and run my Maven unit tests for a Java 11, while having my code compiled for an older version of Java 8 如何将整数(例如 19000101 )转换为 java.util.Date? - How can I convert an Integer (e.g 19000101 ) to java.util.Date? 我可以用较新的JDK用ant编译Java较旧版本的Java,以便在编译使用较新API的代码时生成输出吗? - Can i compile java for an older Java version with ant with a newer JDK so it generates output when it compiles code that uses the newer API? 我可以在旧版本的Elasticsearch上使用新版本的Java高级别Rest客户端吗? - Can I use newer version of java high level rest client on an older version of elasticsearch? Java枚举上的按位运算; RE:国际象棋 - Bitwise operations on Java Enumerations; RE: Chess E.G 将值保存到 java 中的文件(例如 yml) - Save values to file(e.g yml) in java 无法使用 Java 10 和 Java 11 运行或导入 JAR - Can't run or import JARs with Java 10 and Java 11 java --version显示10但已安装Java 11 - java --version shows 10 but java 11 is installed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM