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

Default constructor of protected inner class cannot be accessed in other package

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.3.0
    • 1.2.0
    • specification
    • None
    • rc3
    • generic
    • generic

      The inner classes spec does not specify the access modifiers to
      be used for the default constructor of a protected or private
      inner class. JLS 8.6.7 specifies that the default constructor
      recieves the 'public' modifier if its class is public, else it
      receives default access (which is the only other access permitted
      for a class in the pre-1.1 language). The program below is thus
      illegal.

      It is highly counterintuitive that a default constructor for a class
      should be inaccessible at any point at which the class might be
      subclassed or instantiated.

      This appears to be an oversight in the inner classes spec.

      -------------------

      package p1;

      public class ProtectedInnerClass1 {
          protected class Foo {
      //OK if constructor is explicitly declared
      //protected Foo() {}
      public String getBar() { return "bar"; }
          }
      }

      -------------------

      package p2;

      public class ProtectedInnerClass2 extends p1.ProtectedInnerClass1
      {
          class Bug extends Foo {
      String getBug() { return getBar(); }
          }
      }

      -------------------

            gbrachasunw Gilad Bracha (Inactive)
            wmaddoxsunw William Maddox (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: