Question about JEP 406
Remi Forax
forax at univ-mlv.fr
Tue Jun 15 20:00:34 UTC 2021
It can be reduced to
sealed interface Exp<T> { }
record Add() implements Exp<Integer> {}
record Lit<T>(T obj) implements Exp<T> {}
Yes, we have missed that case.
When a subtype of a sealed type is not a subtype of the type switch upon, it should be discarded when testing exhaustiveness.
Thanks,
Rémi
----- Mail original -----
> De: "Jim Laskey" <james.laskey at oracle.com>
> À: "amber-dev" <amber-dev at openjdk.java.net>
> Cc: "Tesla Ice Zhang" <ice1000kotlin at foxmail.com>
> Envoyé: Mardi 15 Juin 2021 18:59:39
> Objet: Re: Question about JEP 406
> [HTML messed up in original code]
>
> sealed interface Exp<T> {
> record Add(Exp<Integer> lhs, Exp<Integer> rhs) implements Exp<Integer> {}
> record Lit<T>(T obj) implements Exp<T> {}
> }
>
>
>> On May 21, 2021, at 2:06 AM, Tesla Ice Zhang <ice1000kotlin at foxmail.com> wrote:
>>
>> Hi OpenJDK developers,
>>
>> I'm very excited about JEP 406. Sealed classes are taken into account in switch
>> expressions, which is great! However, there is one special case not mentioned
>> in the JEP, about generic sealed interfaces:
>>
>>
>> sealed interface Exp<T> {
>> record Add(Exp<Integer> lhs, Exp<Integer> rhs) implements
>> Exp<Integer> {}
>> record Lit<T>(T obj) implements Exp<T> {}
>> }
>>
>>
>>
>> In the above example, if we do a switch on an expression of type
>> Exp<Boolean>, do we need to provide a case for Add?
>>
>>
>> Best regards,
> > Tesla
More information about the amber-dev
mailing list