Skip to content
UniCircle
MediumConceptualControl flow

Classic switch vs switch expressions

Question JAVA-OPS-008

What problem does fall-through cause in a classic switch, and how do modern switch expressions (Java 14+) fix it?

Show the explanation

In a classic switch, execution falls through to the next case unless you write break. Forgetting one is a classic bug:

Java
switch (day) {
    case "SAT": type = "weekend";      // missing break
    case "MON": type = "weekday";      // SAT ends up "weekday"
}

A switch expression uses arrows, never falls through, can list several labels per case, and returns a value. When used as an expression over an enum or sealed type, the compiler checks that every case is covered:

Java
String type = switch (day) {
    case "SAT", "SUN" -> "weekend";
    case "MON", "TUE", "WED", "THU", "FRI" -> "weekday";
    default -> throw new IllegalArgumentException(day);
};

For a multi-line branch use a block with yield value;. switch works on int-like primitives, their wrappers, String and enums — and, since Java 21, on any type with pattern matching (case Circle c -> …).

Original UniCircle question. Last reviewed 22 Oct 2026.