Selaed classes cant permit private classes
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Mon Aug 26 13:51:31 UTC 2024
On 26/08/2024 14:44, Maurizio Cimadamore wrote:
> That is, an “extends” or “permits” clause is not really type-checked
> as if inside the body of class C. This results in the accessibility
> problem you point out (which might or might not be a compiler glitch,
> I don’t think the JLS is crystal clear on how Tmp.A should be checked).
I stand corrected - see JLS 6.6:
> A member (class, interface, field, or method) of a class, interface,
> type parameter, or reference type, or a constructor of a class, is
> accessible only if (i) the class, interface, type parameter, or
> reference type is accessible, and (ii) the member or constructor is
> declared to permit access:
> [...]
>
> *
>
> Otherwise, the member or constructor is declared |private|.
> Access is permitted only when one of the following is true:
>
> o
>
> Access occurs from within the body of the top level class or
> interface that encloses the declaration of the member or
> constructor.
>
> o Access occurs in the |permits| clause of the top level class
> or interface that encloses the declaration of the member.
> o
>
> Access occurs in the record component list of the top level
> record class that encloses the declaration of the member.
>
So, there's special accessibility pleads for "permits" clauses. So yes,
this is a javac bug.
I've added some comments to JDK-8338981.
Maurizio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240826/e5a69b29/attachment.htm>
More information about the amber-dev
mailing list