> De: "Gavin Bierman" <gavin.bier...@oracle.com> > À: "Remi Forax" <fo...@univ-mlv.fr> > Cc: "amber-spec-experts" <amber-spec-experts@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:fo...@univ-mlv.fr | >> fo...@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