New candidate JEP: 455: Primitive types in Patterns, instanceof, and switch (Preview)

Brian Goetz brian.goetz at oracle.com
Tue Sep 26 13:06:54 UTC 2023


 > Under the David rules, this switch is not exhaustive,
> > because it matches neither Pair(null, _) or
> > Pair(_, null). So what cases would you have to add to the
> > switch to satisfy the compiler's complaints of
> > non-exhaustiveness?  Write the code, and then tell me if
> > you want to program in that language...
>
> Excellent example lol. That clarifies it perfectly. So, the reason why 
> we do not want to have this level of specificity required by the 
> programmer is because it would cascade into a giant pile of writing 
> down edge cases. Makes perfect sense.

Yes.  And it is not that I am against asking users to write down the 
edge cases when it makes sense, but here it makes no sense.  Being 
explicit about the potential combinatorial explosion of edge cases will 
not make anyone's code better, and will more likely encourage developers 
to achieve totality by sticking a default clause on -- which means worse 
exhaustiveness checking which in turn means less reliable programs.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jdk-dev/attachments/20230926/8b51456a/attachment.htm>


More information about the jdk-dev mailing list