---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 8 Edition"
java_version: 8
chapter: "Chapter 18. Type Inference"
section: "18.2.4"
heading: "18.2.4. Type Equality Constraints"
parent: "18.2. Reduction"
source: https://docs.oracle.com/javase/specs/jls/se8/html/jls-18.html#jls-18.2.4
id: "18.2.4"
url: https://jvm.obfuscated.software/jls/se8/18.2.4.html
raw: https://jvm.obfuscated.software/jls/se8/18.2.4.md
---

# 18.2.4. Type Equality Constraints

A constraint formula of the form ‹S = T›, where S and T are types, is reduced as follows:

- If S and T are proper types, the constraint reduces to *true* if S is the same as T ([§4.3.4](4.3.4.md)), and *false* otherwise.
- Otherwise, if S or T is the null type, the constraint reduces to *false*.
- Otherwise, if S is an inference variable, α, and T is not a primitive type, the constraint reduces to the bound α = T.
- Otherwise, if T is an inference variable, α, and S is not a primitive type, the constraint reduces to the bound S = α.
- Otherwise, if S and T are class or interface types with the same erasure, where S has type arguments B_1, ..., B_n and T has type arguments A_1, ..., A_n, the constraint reduces to the following new constraints: for all *i* (1 ≤ *i* ≤ *n*), ‹B_i = A_i›.
- Otherwise, if S and T are array types, S'`[]` and T'`[]`, the constraint reduces to ‹S' = T'›.
- Otherwise, the constraint reduces to *false*.

Note that we do not address intersection types above, because it is impossible for reduction to encounter an intersection type that is not a proper type.

A constraint formula of the form ‹S = T›, where S and T are type arguments ([§4.5.1](4.5.1.md)), is reduced as follows:

- If S and T are types, the constraint is reduced as described above.
- If S has the form `?` and T has the form `?`, the constraint reduces to *true*.
- If S has the form `?` and T has the form `?` `extends` T', the constraint reduces to ‹`Object` = T'›.
- If S has the form `?` `extends` S' and T has the form `?`, the constraint reduces to ‹S' = `Object`›.
- If S has the form `?` `extends` S' and T has the form `?` `extends` T', the constraint reduces to ‹S' = T'›.
- If S has the form `?` `super` S' and T has the form `?` `super` T', the constraint reduces to ‹S' = T'›.
- Otherwise, the constraint reduces to *false*.
