Exhaustiveness in switch

Guy Steele guy.steele at oracle.com
Thu May 10 20:46:31 UTC 2018

> On May 10, 2018, at 4:54 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
>> * It would feel strange to even bother applying this exhaustiveness goo to byte switches. If we ever had ranges.... of course then, any type of switch could join the party. (I don't know whether ranges are a thing we're considering or not and I'm not pushing that we do.)
> Yeah, its on the edge.  Its a no-brainer for `boolean`, its nuts for `int` (without ranges), but its vaguely defensible for `byte`.  Though I can't really get too excited about it.

The choice is not just among four sizes of integer.  One could imagine recognizing certain idioms such as

	switch (myInt & 7) {
	  case 2, 3, 5, 7 -> “prime”;
	  case 0, 1, 4 -> “square”;
	  case 6 -> “perfect”;

and understanding that they are exhaustive.  Dunno if the compiler guys want to go there.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20180510/d163d4ae/attachment.html>

More information about the amber-spec-experts mailing list