java compilation : source, target and release supported versions

倾然丶 夕夏残阳落幕 提交于 2019-12-23 01:15:13

问题


I may do some cross-compilations for legacy projects and I noticed with recent JDKs that we are limited to some specific versions for the source, target and release JVM arguments.
How to get the supported versions for these arguments ?


回答1:


Indeed the supported values depend on the major JDK version used.
You can find the information on the javac documentation of the respective major JDK versions (the links are referenced below).

Some general notes about these arguments :

  • The source and the target version in the Maven configuration should not be superior to the JDK version used.
    A older version of the JDK cannot compile with a more recent version since it doesn't know its specification.

  • The release argument exists from Java 9.

  • As the source and the target are the same, the release argument should be favored over source and target. It is shorter to specify and it ensures a better cross compilation compatibility and whatever even if you don't do cross compilations, it will not hurt.
    For more explanations please refer to this excellent answer.

source/target/release supported versions :

For Java 7

  • supported source :

1.3, 1.4, 1.5 (also 5), 1.6 (also 6), and 1.7 (also 7).

  • supported target :

1.1, 1.2, 1.3, 1.4, 1.5 (also 5), 1.6 (also 6), and 1.7 (also 7).

For Java 8

  • supported source :

1.3, 1.4, 1.5 (also 5), 1.6 (also 6), 1.7 (also 7), and 1.8 (also 8).

  • supported target :

1.1, 1.2, 1.3, 1.4, 1.5 (also 5), 1.6 (also 6), 1.7 (also 7), and 1.8 (also 8).

For Java 9

  • supported source :

1.6 (also 6), 1.7 (also 7), 1.8 (also 8), and 9.

  • supported target :

1.6 (also 6), 1.7 (also 7), 1.8 (also 8) and 9.

  • supported release :

6, 7, 8, and 9.

For Java 10

  • supported source :

1.6 (also 6), 1.7 (also 7), 1.8 (also 8), 9, and 10.

  • supported target :

1.6 (also 6), 1.7 (also 7), 1.8 (also 8), 9 and 10.

  • supported release :

6, 7, 8, 9, and 10.

You could have more details in the javac documentation for JDK 1.8, JDK 9 and JDK 10



来源:https://stackoverflow.com/questions/51692748/java-compilation-source-target-and-release-supported-versions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!