Switch expressions -- gathering the threads

Remi Forax forax at univ-mlv.fr
Tue Apr 10 20:30:53 UTC 2018

> De: "daniel smith" <daniel.smith at oracle.com>
> À: "Brian Goetz" <brian.goetz at oracle.com>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Mardi 10 Avril 2018 21:34:13
> Objet: Re: Switch expressions -- gathering the threads

>> On Apr 9, 2018, at 1:14 PM, Brian Goetz < [ mailto:brian.goetz at oracle.com |
>> brian.goetz at oracle.com ] > wrote:

>> A form of fallthrough that I think may be more common in expression switches is
>> when something wants to fall _into_ the default:

>> int x = switch (y) {
>> case "Foo" -> 1;
>> case "Bar" -> 2;

>> case null:
>> default:
>> // handle exceptional case here
>> }

>> Because `default` is not a pattern, we can't say:

>> case null, default:

>> here. (Well, we could make it one.) Though we could carve out an exception for
>> such "trivial" fallthrough.

> As a matter of terminology, I think it would be helpful for us to not call this
> fallthrough at all. It creates a lot of confusion when somebody is making an
> assertion about fallthrough, and it's unclear whether this kind of thing is
> being included or not.

> JLS is a good guide: grammatically, the body of a switch statement is a sequence
> of SwitchBlocks, each of which has a sequence of SwitchLabels followed by some
> BlockStatements.

> [ https://docs.oracle.com/javase/specs/jls/se10/html/jls-14.html#jls-14.11 |
> https://docs.oracle.com/javase/specs/jls/se10/html/jls-14.html#jls-14.11 ]

> JLS doesn't formally define the concept of "fallthrough" but I suggest we use it
> to describe the situation in which control flows from one SwitchBlock to
> another.

> What you've illustrated is instead a "switch case with multiple
> labels"—something deserving scrutiny on its own, but really a different sort of
> problem than fallthrough.

> —Dan

I'm not sure this difference is important. 

What about the example below, multiple labels or a fallthrough ? 
switch(x) { 
case 0: 
case 1: 


More information about the amber-spec-observers mailing list