Java 12 introduced switch expressions and Java 13 refined them as a preview feature. The key improvements include: switch can now be used as an expression that evaluates to a value, a new arrow-form syntax (case X -> result) that prevents fall-through, the yield keyword to return values from blocks, support for multiple labels per case, and compiler-enforced exhaustiveness for switch expressions over enums. The arrow-form is distinct from the colon-form in that it eliminates fall-through behavior regardless of whether switch is used as an expression or statement. The guide covers poly expression typing, restrictions on early returns inside switch expressions, and how the compiler handles exhaustiveness checks.
Table of contents
▚ Trouble With Switch Statements▚ Enter Switch Expressions!▚ Switch Evolution In Depth▚ Arrow-Form In Depth▚ Switch Expressions In Depth▚ ReflectionSort: