To use records with JDK 15, I used to compile with arguments --enable-preview --release 15
passed to javac on my Ant build. Everything compiled and run fine.
When using JDK 16, if I compile with the same arguments, I get
error: invalid source release 15 with --enable-preview (preview language features are only supported for release 16)
Records are a standard feature of JDK 16, so I expected that I should compile without those arguments. However, If I remove them, I get
Foo.class uses preview features of Java SE 15. (use --enable-preview to allow loading of classfiles which contain preview features)
And Ant reports a compilation failure:
Compile failed; see the compiler error output for details. at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1425)
So, its a compilation failure with the flags and without them. What's wrong?