---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 22 Edition"
java_version: 22
chapter: "Chapter 16. Definite Assignment"
section: "16.2.9"
heading: "16.2.9. switch Statements"
parent: "16.2. Definite Assignment and Statements"
source: https://docs.oracle.com/javase/specs/jls/se22/html/jls-16.html#jls-16.2.9
id: "16.2.9"
url: https://jvm.obfuscated.software/jls/se22/16.2.9.html
raw: https://jvm.obfuscated.software/jls/se22/16.2.9.md
---

# 16.2.9. `switch` Statements

- V is [un]assigned after a `switch` statement ([§14.11](14.11.md)) iff all of the following are true:

  - V is [un]assigned before every `break` statement ([§14.15](14.15.md)) that may exit the `switch` statement.
  - For each switch rule ([§14.11.1](14.11.1.md)) in the switch block, V is [un]assigned after the switch rule expression, switch rule block, or switch rule `throw` statement introduced by the switch rule.
  - If there is a switch labeled statement group in the switch block, then V is [un]assigned after the last block statement of the last switch labeled statement group.
  - If the `switch` statement is not exhaustive ([§14.11.1.1](14.11.1.1.md)), or if the switch block ends with a switch label followed by the `}` separator, then V is [un]assigned after the selector expression.

- V is [un]assigned before the selector expression of a `switch` statement iff V is [un]assigned before the `switch` statement.

- V is [un]assigned before any guard associated with the switch block of a `switch` statement iff V is [un]assigned after the selector expression.

- V is [un]assigned before the switch rule expression, switch rule block, or switch rule `throw` statement introduced by a switch rule in the switch block iff V is [un]assigned after the selector expression of the `switch` statement.

- V is [un]assigned before the first block statement of a switch labeled statement group in the switch block iff both of the following are true:

  - V is [un]assigned after the selector expression of the `switch` statement.
  - If the switch labeled statement group is not the first in the switch block, V is [un]assigned after the last block statement of the preceding switch labeled statement group.

- V is [un]assigned before a block statement that is not the first of a switch labeled statement group in the switch block iff V is [un]assigned after the preceding block statement.
