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

# 16.2.7. `if` Statements

The following rules apply to a statement `if (e) S` ([§14.9.1](14.9.1.md)):

- V is [un]assigned after `if (e) S` iff V is [un]assigned after S and V is [un]assigned after `e` when false.
- V is [un]assigned before `e` iff V is [un]assigned before `if (e) S`.
- V is [un]assigned before S iff V is [un]assigned after `e` when true.

The following rules apply to a statement `if (e) S else T` ([§14.9.2](14.9.2.md)):

- V is [un]assigned after `if (e) S else T` iff V is [un]assigned after S and V is [un]assigned after T.
- V is [un]assigned before `e` iff V is [un]assigned before `if (e) S else T`.
- V is [un]assigned before S iff V is [un]assigned after `e` when true.
- V is [un]assigned before T iff V is [un]assigned after `e` when false.
