---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 26 Edition"
java_version: 26
chapter: "Chapter 15. Expressions"
section: "15.3"
heading: "15.3. Type of an Expression"
parent: "Chapter 15. Expressions"
source: https://docs.oracle.com/javase/specs/jls/se26/html/jls-15.html#jls-15.3
id: "15.3"
url: https://jvm.obfuscated.software/jls/se26/15.3.html
raw: https://jvm.obfuscated.software/jls/se26/15.3.md
---

# 15.3. Type of an Expression

If an expression denotes a variable or a value, then the expression has a type known at compile time. The type of a standalone expression can be determined entirely from the contents of the expression; in contrast, the type of a poly expression may be influenced by the expression's target type ([§5 (*Conversions and Contexts*)](5.md)). The rules for determining the type of an expression are explained separately below for each kind of expression.

The value of an expression is assignment compatible ([§5.2](5.2.md)) with the type of the expression, unless heap pollution occurs ([§4.12.2](4.12.2.md)).

Likewise, the value stored in a variable is always compatible with the type of the variable, unless heap pollution occurs.

In other words, the value of an expression whose type is T is always suitable for assignment to a variable of type T.

Note that if the type of an expression is a class type which names the class C, then the declaration of class C as `final` or `sealed` ([§8.1.1.2](8.1.1.2.md)) has implications for the value of the expression:

- If C is `final`, then the expression is guaranteed to have a value that is either (i) the null reference, or (ii) an object whose class is C itself, because `final` classes have no subclasses.
- If C is `sealed`, then the expression is guaranteed to have a value that is either (i) the null reference, (ii) an object whose class is C itself, or (iii) assignment compatible with one of the permitted direct subclasses of C ([§8.1.6](8.1.6.md)).
- If C is freely extensible, then the expression is guaranteed to have a value that is either (i) the null reference, (ii) an object whose class is C itself, or (iii) assignment compatible with C.
