-
Enhancement
-
Resolution: Fixed
-
P4
-
18
The legality of the following program depends on whether the scope of the simple name D is (i) just the RecordBody of C, not the RecordHeader `(D x)`; or (ii) the RecordBody of C _and_ the RecordHeader.
record C(D x) {
class D {}
}
If (i), then the record component `D x` is illegal (D not in scope).
If (ii), then the record component is legal.
The record component _should_ be legal because the program is specified by 8.10.3 to be equivalent to the following declaration of C, which is plainly legal:
class C {
private final D x = ...;
public D x() { ... }
class D {}
}
It's unreasonable to ask people to sketch out the equivalent program in order to figure scope. 6.3 should clarify that "The scope of a declaration of a member m declared in or inherited by a class or interface C (§8.2, §9.2) is the entire body of C, including any nested class or interface declarations. ***If C is a record class, then the scope of m additionally includes the header of the record declaration of C.***"
record C(D x) {
class D {}
}
If (i), then the record component `D x` is illegal (D not in scope).
If (ii), then the record component is legal.
The record component _should_ be legal because the program is specified by 8.10.3 to be equivalent to the following declaration of C, which is plainly legal:
class C {
private final D x = ...;
public D x() { ... }
class D {}
}
It's unreasonable to ask people to sketch out the equivalent program in order to figure scope. 6.3 should clarify that "The scope of a declaration of a member m declared in or inherited by a class or interface C (§8.2, §9.2) is the entire body of C, including any nested class or interface declarations. ***If C is a record class, then the scope of m additionally includes the header of the record declaration of C.***"
- relates to
-
JDK-8282913 8.10.1: Clarify scope of record components
- Resolved
-
JDK-8284011 6.6.1: Clarify that a private member class can be used in a permits clause and as a record component
- Resolved