I have a simple Java class which contains an anonymous inner class:
package stackoverflow;
public class Outer
{
public static void main(final String[] arguments)
{
System.out.println(new Object() {});
}
}
With mvn compile
running javap Outer*
gives class stackoverflow.Outer$1 {
, whereas with ./gradlew compileJava
and plain javac
I get final class stackoverflow.Outer$1 {
.
Which configuration option causes the added/missing final
?
I'm using Java 1.8.0_232 (OpenJDK), Gradle 6.5, Maven 3.6.3 (maven-compiler-plugin:3.6.1)
EDIT: Although this is marked as a duplicate, you won't find the answer in the linked question. In my case the final
does not appear if I compile with "errorprone". If I disable "errorprone", I also get final
in the resulting .class
file using Maven. Errorprone (in my project) compiles using Java 9, whereas the plain project uses Java 8. See https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.9.5 and https://docs.oracle.com/javase/specs/jls/se9/html/jls-15.html#jls-15.9.5.