Selaed classes cant permit private classes
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Mon Aug 26 18:32:12 UTC 2024
For "extends" at the class level, I think in reality you end up with
cyclic inheritance, so there's not much to do.
For "extends" in a type-parameter, that's a valid question - althugh, if
you think about it, having a class with a type-variable whose bound is a
_private_ member of that class, seems not too useful (the only place
where you can parameterize instances of that class correctly is that
class itself).
Maurizio
On 26/08/2024 15:09, Olexandr Rotan wrote:
> So there is a special case for permits clause, but what about extends
> clause? Should I also look into it, or, formally, this is a different
> issue that requires (arguably) JLS change?
>
> On Mon, Aug 26, 2024 at 4:51 PM Maurizio Cimadamore
> <maurizio.cimadamore at oracle.com> wrote:
>
>
> 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/f0633bcf/attachment-0001.htm>
More information about the amber-dev
mailing list