Is it possible to compile Java11 code to Java8 bytecode and run on 8?

It is possible now with https://github.com/bsideup/jabel

Jabel - javac 12 plugin that makes it emit Java 8 bytecode


It is not possible. Only the API methods and classes of the targeted Java platform are allowed.

That is defined in JEP 247: Compile for Older Platform Versions

A new command-line option, --release, is defined, which automatically configures the compiler to produce class files that will link against an implementation of the given platform version.

The relevant part that says what can be used is:

For N < 9, the documented APIs consist of the public APIs that were on javac's default bootclasspath for JDK N.

For N >= 9, the documented APIs consist of (i) the APIs exported from those modules in the JDK image which are part of the documentation of JDK N; and (ii) the API exported from the jdk.unsupported module (documented in JEP 260).

Tags:

Java

Maven