---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 26 Edition"
java_version: 26
chapter: "Chapter 6. Names"
section: "6.3.3"
heading: "6.3.3. Scope for Pattern Variables in case Labels"
parent: "6.3. Scope of a Declaration"
source: https://docs.oracle.com/javase/specs/jls/se26/html/jls-6.html#jls-6.3.3
id: "6.3.3"
url: https://jvm.obfuscated.software/jls/se26/6.3.3.html
raw: https://jvm.obfuscated.software/jls/se26/6.3.3.md
---

# 6.3.3. Scope for Pattern Variables in `case` Labels

Pattern variables can be introduced by `case` labels with a `case` pattern, either by the pattern itself or by a guard, and are in scope for the relevant parts of the associated `switch` expression ([§6.3.1.6](6.3.1.6.md)) or `switch` statement ([§6.3.2.6](6.3.2.6.md)).

The following rules applies to `case` labels:

- A pattern variable is introduced by a `case` label with a `case` pattern `p` if `p` contains a declaration of the pattern variable.
- If a `case` pattern in a guarded `case` label contains a declaration of a pattern variable then the pattern variable is definitely matched in the associated guard.
- A pattern variable is introduced by a guarded `case` label if it is introduced by the associated guard when true ([§6.3.1](6.3.1.md)).
