Record component type can be an inner class of a record
forax at univ-mlv.fr
forax at univ-mlv.fr
Mon Apr 13 17:08:10 UTC 2020
> De: "Gavin Bierman" <gavin.bierman at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Lundi 13 Avril 2020 18:37:14
> Objet: Re: Record component type can be an inner class of a record
> Thanks for pointing this out Remi. We definitely need to tweak the draft spec to
> deal with this scoping question.
> However, I am of the opinion that this example should not be allowed. I would
> expect the scope of things defined in a record body to be the record body. I
> don’t think the record header should be considered part of the body.
> Analogously:
> class Foo<T extends Bar> {
> class Bar { … }
> …
> }
> This doesn’t work as the scope of the Bar declaration is the class body.
> What do you think?
I believe you're right, the following code should not compile, apart if you want to write puzzler for a living :)
class A { int y; }
record B(A a) implements I {
public static void main(String[] args) {
System.out.println(new B(null).a().x);
}
}
interface I {
class A { int x; }
}
> Gavin
Rémi
>> On 24 Mar 2020, at 20:57, Remi Forax < [ mailto:forax at univ-mlv.fr |
>> forax at univ-mlv.fr ] > wrote:
>> Hi all,
>> a record component can use as type a type declared inside the record itself,
>> in term of scoping it's like if the record component is part of the internal
>> scope of the record.
>> record Foo(Bar bar) {
>> class Bar {
>> }
>> }
>> I think it's the right behaviour but i was not able to find any reference to
>> that in the spec.
>> regards,
>> Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20200413/4e36d72b/attachment.htm>
More information about the amber-spec-experts
mailing list