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

Inaccessible instance error in enum falsely flagged as static context

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      https://stackoverflow.com/questions/41311361/nested-enum-is-static#41311454 describes the following program:

      enum EnumImpl {
          B {
              public void method() {
                  System.out.println(s);
              }
              //public static int b; //(2)Illegal static declaration in inner class
          };
          public abstract void method();
          private int s;
      }

      The compiler error message is:

      non-static variable s cannot be referenced from a static context

      This message is misleading. If "private" is removed from the declaration of s, the class compiles as it should. The reason for failure should be described as "s has private access in EnumImpl".


      FREQUENCY : always


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: