Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6510286

Wording of javac error for inner classes

XMLWordPrintable

    • b128
    • generic
    • generic
    • Verified

      Compiling
        B b = new B() { static final int x; };
      gives error
        inner classes cannot have static declarations

      but they can, provided the static declaration is a compile-time constant field (JLS8.1.3):
        B b = new B() { static final int x = 1; }; // Compiles OK

      (I'll update the JLS to say "unless they are constant variables (4.12.4)" rather than "compile-time constant fields (15.28)".)

            mcimadamore Maurizio Cimadamore
            abuckley Alex Buckley
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: