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

6.6.1: Clarify that a private member class can be used in a permits clause and as a record component

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 18
    • Fix Version/s: 19
    • Component/s: specification
    • Labels:

      Description

      The following declaration is illegal because the member class X.Y cannot be accessed in the `permits` clause:

      sealed class X permits X.Y {
          private static final class Y extends X {}


      (Note that this issue is about accessibility, not scope. Scope involves simple names, such as `Y`, but the `permits` clause above uses a qualified name, `X.Y`.)

      The illegality of accessing `X.Y` is inconsistent with the legality of the following equivalent code, where the `permits` clause is implicitly declared:

      sealed class X {
          private static final class Y extends X {}


      The text in 6.6.1 concerning access of a private member should be clarified as follows:

      -----
      Otherwise, the member or constructor is declared private. Access is permitted only when one of the following is true:
      - Access occurs from within the body of the top level class or interface that encloses the declaration of the member or constructor.
      - Access occurs in the `permits` clause of the top level class or interface that encloses the declaration of the member.
      - Access occurs in the record component list of the top level record class that encloses the declaration of the member.
      -----


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              gbierman Gavin Bierman
              Reporter:
              gbierman Gavin Bierman
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: