[records] static final fields without initializer are accepted by javac

Tagir Valeev amaembo at gmail.com
Sat Jan 4 15:16:49 UTC 2020


The following code can be compiled by javac:

record Test() {
  static final int x;

  public static void main(String[] args) {

>"C:\Program Files\Java\jdk-14\bin\java.exe" --enable-preview --source=14 Test.java
Note: Test.java uses preview language features.
Note: Recompile with -Xlint:preview for details.

>"C:\Program Files\Java\jdk-14\bin\java.exe" --version
openjdk 14-ea 2020-03-17
OpenJDK Runtime Environment (build 14-ea+28-1366)
OpenJDK 64-Bit Server VM (build 14-ea+28-1366, mixed mode, sharing)

Javac correctly rejects the code if we change `record Test()` to `class Test`.

With best regards,
Tagir Valeev.

More information about the amber-dev mailing list