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 (e.g 9, 10, 11 etc.) versions, and have that Java be compiled down to some older version - such as Java 8? We would like to use...

问题:

Is it possible to develop using newer Java (e.g 9, 10, 11 etc.) versions, and have that Java be compiled down to some older version - such as 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.

If it matters: we are building with Maven.


Phrasing it in Javascript fashion:

Does there exist a Babel Polyfill equivalence for Java?


回答1:

No - you cannot use new features on an older 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.

If you need the new features of newer Java versions, then it's time to migrate to a new version; other than that, where you are will be fine until you require support from Oracle.


回答2:

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. 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?

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.

  • 发表于 2019-03-29 22:36
  • 阅读 ( 213 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除