I have read about source
and target
options for javac
that they define a version that my source code requires to compile and oldest JRE version i want to support, respectively. While using Maven build tool i have defined these parameters in pom.xml like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>15</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
, but target version can not be set lower than source version, why is it so?
Trying to compile with this configuration results in error: "Fatal error compiling: warning: source release 15 requires target release 15". Same with any other combination of source version being higher than target.
invokedynamic
. Therefore targeting a JVM version earlier than the one that got those features added would break: you'd produce bytecode that the target JVM can't interpret. There is a workaround, that's called "retrocompiling", but it's not offered byjavac
itself, but some third party tools can do it. – Apace