A case statement selects a switch branch by matching the switch expression. In classic Java switch syntax, execution falls through into the next case unless an explicit break, return, or equivalent exit stops it. section 3.3
Accidental fall-through
If a case omits break, multiple actions may run: a YES branch can execute its action and then continue into the NO branch. Mark intentional fall-through with // fallthrough so both readers and static analyzers can distinguish it from a mistake. section 3.3
Prefer these patterns when writing case branches:
- Use arrow syntax, such as case YES -> actOnYes(), when Java 14 or newer is available; it prevents fall-through. section 3.3
- Shape branches to return a value or assign one shared variable; declaring that variable final can make accidental repeated assignment fail compilation. section 3.3
- Use static analysis to find likely omissions: SonarLint, SpotBugs, and IntelliJ IDEA provide fall-through warnings, though intentional flow may require an annotation comment. section 3.3








