What is the meaning of this Java code?

I recently managed to write a piece of code similar to this:

switch (x) {
    case a: case b: case c:
    // do something
    break;
    case d: case e: case f:
    // do something
    break;
}

Then I made a mistake and wrote a similar code with a syntax error: I forgot to write the case keyword:

switch (x) {
    case a: b: c:
    // do something
    break;
    case d: e: f:
    // do something
    break;
}

This syntax is valid in some other languages, and the switch goes through all the values.

In fact, this is also relevant, since I did not receive a syntax error: but the incorrect behavior of the program that ran the switch smoothly only passed values ​​without the case keyword.

Why? What is b; c :, e: and f: average in the second snip?

Are they shortcuts ? And then, how can they be on the same line? What am I missing, what I don’t understand behind this strange mistake?

Edit: they really are shortcuts . , , @Bathsheba, , . , Java ( ) , . .

.

+4
1

b:, c:, e: f: - . break Java, , , .

, , .

+5

Source: https://habr.com/ru/post/1663988/


All Articles