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

8.10.1: Clarify scope of record components



    • Enhancement
    • Resolution: Fixed
    • P4
    • 19
    • 18
    • specification


      Many sections in Ch.8 have a sentence that says "The scope and shadowing of a XYZ declaration is specified in §6.3 and §6.4.1." However, section 8.10.1 Record Components does not. Why? Because a record component is not a declaration. Rather, a record component _corresponds_ to two members of the record class: a private field declared implicitly, and a public accessor method declared explicitly or implicitly. Section 6.1 Declarations is careful to speak about the field declaration and method declaration, and never mentions a "record component declaration".

      Since a record component is not a declaration, it has no scope of its own. The scope of the record component's corresponding field and method are specified as usual by 6.3. Namely, they can be referenced by simple name in the body of the record declaration, but not in its header (the RecordComponentList).

      It would be proper for 8.10.3 to say:

      "The scope and shadowing of the component field and the accessor method are specified in §6.3 and §6.4.1. (The record component to which they correspond is not a declaration, so has no scope of its own.)"

      It would also be proper for 8.10.1 to speak more carefully about the record component, to avoid implying it is a declaration (which would mean having a scope):

      - The rules concerning annotation modifiers for a record component declaration ...
      - Annotations on a record component declaration ...
      - It is a compile-time error for a record declaration to declare a record component with the name ...
      - It is a compile-time error for a record declaration to declare two record components with the same name.


        Issue Links



              gbierman Gavin Bierman
              abuckley Alex Buckley
              0 Vote for this issue
              1 Start watching this issue