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

# 18.3. Incorporation

As bound sets are constructed and grown during inference, it is possible that new bounds can be inferred based on the assertions of the original bounds. The process of *incorporation* identifies these new bounds and adds them to the bound set.

Incorporation can happen in two scenarios. One scenario is that the bound set contains complementary pairs of bounds; this implies new constraint formulas, as specified in [§18.3.1](18.3.1.md). The other scenario is that the bound set contains a bound involving capture conversion; this implies new bounds and may imply new constraint formulas, as specified in [§18.3.2](18.3.2.md). In both scenarios, any new constraint formulas are reduced, and any new bounds are added to the bound set. This may trigger further incorporation; ultimately, the set will reach a fixed point and no further bounds can be inferred.

If incorporation of a bound set has reached a fixed point, and the set does not contain the bound *false*, then the bound set has the following properties:

- For each combination of a proper lower bound `L` and a proper upper bound U of an inference variable, `L` `<:` U.
- If every inference variable mentioned by a bound has an instantiation, the bound is satisfied by the corresponding substitution.
- Given a dependency α = β, every bound of α matches a bound of β, and vice versa.
- Given a dependency α `<:` β, every lower bound of α is a lower bound of β, and every upper bound of β is an upper bound of α.

The assertion that incorporation reaches a fixed point oversimplifies the matter slightly. Building on the work of Kennedy and Pierce, *[On Decidability of Nominal Subtyping with Variance](http://research.microsoft.com/apps/pubs/default.aspx?id=64041)*, this property can be proven by making the argument that the set of types that may appear in the bound set is finite. The argument relies on two assumptions:

- New capture variables are not generated when reducing subtyping constraints ([§18.2.3](18.2.3.md)).
- Expansive inheritance paths are not pursued.

This specification does not currently guarantee these properties (it is imprecise about the handling of wildcards when reducing subtyping constraints, and does not detect expansive inheritance paths), but may do so in a future version. (This is not a new problem: the Java subtyping algorithm is also at risk of non-termination.)

## 18.3.1. Complementary Pairs of Bounds

(In this section, S and T are inference variables or types, and U is a proper type. For conciseness, a bound of the form α = T may also match a bound of the form T = α.)

When a bound set contains a pair of bounds that match one of the following rules, a new constraint formula is implied:

- α = S and α = T imply ‹S = T›
- α = S and α `<:` T imply ‹S `<:` T›
- α = S and T `<:` α imply ‹T `<:` S›
- S `<:` α and α `<:` T imply ‹S `<:` T›
- α = U and S = T imply ‹S`[`α:=U`]` = T`[`α:=U`]`›
- α = U and S `<:` T imply ‹S`[`α:=U`]` `<:` T`[`α:=U`]`›

When a bound set contains a pair of bounds α `<:` S and α `<:` T, and there exists a supertype of S of the form G`<`S_1, ..., S_n`>` and a supertype of T of the form G`<`T_1, ..., T_n`>` (for some generic class or interface, G), then for all *i* (1 ≤ *i* ≤ *n*), if S_i and T_i are types (not wildcards), the constraint formula ‹S_i = T_i› is implied.

## 18.3.2. Bounds Involving Capture Conversion

When a bound set contains a bound of the form G`<`α_1, ..., α_n`>` = capture(G`<`A_1, ..., A_n`>`), new bounds are implied and new constraint formulas may be implied, as follows.

Let P_1, ..., P_n represent the type parameters of G and let B_1, ..., B_n represent the bounds of these type parameters. Let θ represent the substitution `[`P_1:=α_1, ..., P_n:=α_n`]`. Let R be a type that is *not* an inference variable (but is not necessarily a proper type).

A set of bounds on α_1, ..., α_n is implied, constructed from the declared bounds of P_1, ..., P_n as specified in [§18.1.3](18.1.3.md).

In addition, for all *i* (1 ≤ *i* ≤ *n*):

- If A_i is not a wildcard, then the bound α_i = A_i is implied.

- If A_i is a wildcard of the form `?`:

  - α_i = R implies the bound *false*
  - α_i `<:` R implies the constraint formula ‹B_i θ `<:` R›
  - R `<:` α_i implies the bound *false*

- If A_i is a wildcard of the form `?` `extends` T:

  - α_i = R implies the bound *false*
  - If B_i is `Object`, then α_i `<:` R implies the constraint formula ‹T `<:` R›
  - If T is `Object`, then α_i `<:` R implies the constraint formula ‹B_i θ `<:` R›
  - R `<:` α_i implies the bound *false*

- If A_i is a wildcard of the form `?` `super` T:

  - α_i = R implies the bound *false*
  - α_i `<:` R implies the constraint formula ‹B_i θ `<:` R›
  - R `<:` α_i implies the constraint formula ‹R `<:` T›
