Allowing cases of an enum to stand alongside cases of another type in a switch expression?
David Alayachew
davidalayachew at gmail.com
Mon Oct 17 03:08:09 UTC 2022
And I guess while I'm here, I will also ask -- putting aside records for a
moment, was there ever an explicit reason why this was not permitted? I can
understand records and enums - one is types, the other is values, so it may
be hard to mix them. But this is ALL values. Is it because it isn't worth
the effort?
sealed interface SealedInterface {}
enum TypeA implements SealedInterface { A; }
enum TypeB implements SealedInterface { B; }
private void mixingEnumsUnderTheSameSealedInterfaceDuringAPatternMatch()
{
final SealedInterface someValue = TypeA.A;
final int result =
switch (someValue)
{
case TypeA.A -> 1;
case TypeB.B -> 2;
};
}
And separately, apologies in advance if these are all old discussion topics
that have been brought up multiple times before. I try to look up the
discussions for these on google, but I don't know if they just aren't
getting indexed or something. Does this mailing list have some sort of
index or search bar that allows me to look up things by topic? The best I
can find is going month by month and guesstimating when the discussion
would have happened at. But I'm sure there must be a better way.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20221016/5b99b890/attachment-0001.htm>
More information about the amber-dev
mailing list