Record component type can be an inner class of a record

forax at univ-mlv.fr forax at univ-mlv.fr
Tue Mar 24 21:13:38 UTC 2020


> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>, "amber-spec-experts"
> <amber-spec-experts at openjdk.java.net>
> Envoyé: Mardi 24 Mars 2020 22:06:07
> Objet: Re: Record component type can be an inner class of a record

> It is kind of weird, though, when Bar is not static, since you can't create a
> Bar without having a Foo in hand, and you can't create a Foo without a Bar. You
> could cheat and do this:

> Foo f = new Foo(null);
> Bar b = f.new Bar(...);
> Foo ff = new Foo(b);

> but I doubt anyone will find this technique useful for anything other than a
> puzzler...
I agree, it makes more sense if Bar is static 
record Foo(Kind kind) { 
enum Kind { ZOR, GLUB } 
} 

especially if it's a refactoring from 
class Foo { 
private final Kind kind; 
enum Kind { ZOR, GLUB } 
... 
} 

Rémi 

> On 3/24/2020 4:57 PM, Remi Forax 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/20200324/5482b7e2/attachment-0001.htm>


More information about the amber-spec-experts mailing list