Record pattern and enhanced for

forax at forax at
Wed Oct 26 09:42:00 UTC 2022

----- Original Message -----
> From: "Brian Goetz" <brian.goetz at>
> To: "Remi Forax" <forax at>, "amber-spec-experts" <amber-spec-experts at>
> Sent: Monday, October 24, 2022 7:06:15 PM
> Subject: Re: Record pattern and enhanced for

>> Hi do not think we have yet discussed about using the record pattern in an
>> enhanced for
>> My first reaction when reading that part of the spec was, ok, cool, a bit weird
>> to not piggyback it on pattern assignment but on the switch instead.
> It's not piggybacked on either.  It's part of the Record Patterns JEP,
> which lets you put record patterns in instanceof, switch, and foreach
> contexts.  (The semantics are indeed similar to pattern assignment, so
> when that comes along, nothing new to learn.)

The thing is that there are two ways to implement assignment + pattern, one is to consider that the pattern should be total on the type of the expression, the other is that it should be equivalent to a switch. The later does not work well because of the remainders (null + new subtypes due to separate compilation).

I believe we have made the right call for switch to not force users to explicitly write the handling of the remainders but we can use a more strict approach for the assignment / inside an enhanced for.


More information about the amber-spec-experts mailing list