> De: "daniel smith" <daniel.sm...@oracle.com> > À: "Brian Goetz" <brian.go...@oracle.com> > Cc: "amber-spec-experts" <amber-spec-experts@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.go...@oracle.com | >> brian.go...@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: } regards, Rémi