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

Incorrect compile error: enum instance accessing private members

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 6u38, 7u9, 8
    • tools
    • windows_7

      FULL PRODUCT VERSION :
      java version " 1.7.0_09 "
      Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
      Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      The code below generates the following compile-time errors:

      error: non-static variable i cannot be referenced from a static context
      A { public int get() { return i; } }

      error: i has private access in E
      B { public int get() { return this.i; } }

      And the lines C and D compile correctly. That is an inconsistent behaviour.

          enum E {
              A { public int get() { return i; } },
              B { public int get() { return this.i; } },
              C { public int get() { return super.i; } },
              D { public int get() { return D.i; } };

              private int i = 0;
              E() { this.i = 1; }
              public abstract int get();
          }


      REPRODUCIBILITY :
      This bug can be reproduced always.

            Unassigned Unassigned
            aefimov Aleksej Efimov
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: