Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 11: What is the difference between javac --release and -source and -target command line parameters? [duplicate]

Does anyone know the difference between using --release and the older -source and -target command line parameters?

In the javac man page: -source Provide source compatibility with specified release -target Generate class files for specific VM version

--release Compile for a specific VM version. Supported targets: 6, 7, 8, 9, 10, 11

Could --release bind both -source and -target to the same version?

like image 450
Nicolas Therrien Avatar asked Feb 23 '19 16:02

Nicolas Therrien


1 Answers

The --release flag not only sets source and target versions, but it also causes the compiler to use the symbol table for the JDK libraries corresponding to the specified release, preventing you from accidentally using APIs that are present in the compilation JDK but not present in the specified version. The --release flag was added later, and in most cases, should replace uses of --source and --target.

like image 81
Brian Goetz Avatar answered Sep 21 '22 22:09

Brian Goetz