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

# 18.2.2. Type Compatibility Constraints

A constraint formula of the form ‹S → T› is reduced as follows:

- If S and T are proper types, the constraint reduces to *true* if S is compatible in a loose invocation context with T ([§5.3](5.3.md)), and *false* otherwise.
- Otherwise, if S is a primitive type, let S' be the result of applying boxing conversion ([§5.1.7](5.1.7.md)) to S. Then the constraint reduces to ‹S' → T›.
- Otherwise, if T is a primitive type, let T' be the result of applying boxing conversion ([§5.1.7](5.1.7.md)) to T. Then the constraint reduces to ‹S = T'›.
- Otherwise, if T is a parameterized type of the form G`<`T_1, ..., T_n`>`, and there exists no type of the form G`<`...`>` that is a supertype of S, but the raw type G is a supertype of S, then the constraint reduces to *true*.
- Otherwise, if T is an array type of the form G`<`T_1, ..., T_n`>[]^k`, and there exists no type of the form G`<`...`>[]^k` that is a supertype of S, but the raw type G`[]^k` is a supertype of S, then the constraint reduces to *true*. (The notation `[]^k` indicates an array type of *k* dimensions.)
- Otherwise, the constraint reduces to ‹S `<:` T›.

The fourth and fifth cases are implicit uses of unchecked conversion ([§5.1.9](5.1.9.md)). These, along with any use of unchecked conversion in the first case, may result in compile-time unchecked warnings, and may influence a method's invocation type ([§15.12.2.6](15.12.2.6.md)).

Boxing T to T' is not completeness-preserving; for example, if T were `long`, S might be instantiated to `Integer`, which is not a subtype of `Long` but could be unboxed and then widened to `long`. We avoid this problem in most cases by giving special treatment to inference-variable return types that we know are already constrained to be certain boxed primitive types; see [§18.5.2.1](18.5.2.1.md).

Similarly, the treatment of unchecked conversion sacrifices completeness in cases in which T is not a parameterized type (for example, if T is an inference variable). It is not usually clear in such situations whether the unchecked conversion is necessary or not. Since unchecked conversions introduce unchecked warnings, inference prefers to avoid them unless it is clearly necessary.
