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

# 18.4. Resolution

Given a bound set that does not contain the bound *false*, a subset of the inference variables mentioned by the bound set may be *resolved*. This means that a satisfactory instantiation may be added to the set for each inference variable, until all the requested variables have instantiations.

Dependencies in the bound set may require that the variables be resolved in a particular order, or that additional variables be resolved. Dependencies are specified as follows:

- Given a bound of one of the following forms, where T is either an inference variable β or a type that mentions β:

  - α = T
  - α `<:` T
  - T = α
  - T `<:` α

  If α appears on the left-hand side of another bound of the form G`<`..., α, ...`>` = capture(G`<`...`>`), then β depends on the resolution of α. Otherwise, α depends on the resolution of β.

- An inference variable α appearing on the left-hand side of a bound of the form G`<`..., α, ...`>` = capture(G`<`...`>`) depends on the resolution of every other inference variable mentioned in this bound (on both sides of the = sign).

- An inference variable α depends on the resolution of an inference variable β if there exists an inference variable γ such that α depends on the resolution of γ and γ depends on the resolution of β.

- An inference variable α depends on the resolution of itself.

Given a set of inference variables to resolve, let V be the union of this set and all variables upon which the resolution of at least one variable in this set depends.

If every variable in V has an instantiation, then resolution succeeds and this procedure terminates.

Otherwise, let { α_1, ..., α_n } be a non-empty subset of uninstantiated variables in V such that (i) for all *i* (1 ≤ *i* ≤ *n*), if α_i depends on the resolution of a variable β, then either β has an instantiation or there is some *j* such that β = α_j; and (ii) there exists no non-empty proper subset of { α_1, ..., α_n } with this property. Resolution proceeds by generating an instantiation for each of α_1, ..., α_n based on the bounds in the bound set:

- If the bound set does not contain a bound of the form G`<`..., α_i, ...`>` = capture(G`<`...`>`) for all *i* (1 ≤ *i* ≤ *n*), then a candidate instantiation T_i is defined for each α_i:

  - If α_i has one or more *proper* lower bounds, `L_1`, ..., `L_k`, then T_i = lub(`L_1`, ..., `L_k`) ([§4.10.4](4.10.4.md)).
  - Otherwise, if the bound set contains `throws` α_i, and each proper upper bound of α_i is a supertype of `RuntimeException`, then T_i = `RuntimeException`.
  - Otherwise, where α_i has *proper* upper bounds U_1, ..., U_k, T_i = glb(U_1, ..., U_k) ([§5.1.10](5.1.10.md)).

  The bounds α_1 = T_1, ..., α_n = T_n are incorporated with the current bound set.

  If the result does not contain the bound *false*, then the result becomes the new bound set, and resolution proceeds by selecting a new set of variables to instantiate (if necessary), as described above.

  Otherwise, the result contains the bound *false*, so a second attempt is made to instantiate { α_1, ..., α_n } by performing the step below.

- If the bound set contains a bound of the form G`<`..., α_i, ...`>` = capture(G`<`...`>`) for some *i* (1 ≤ *i* ≤ *n*), or;

  If the bound set produced in the step above contains the bound *false*;

  then let Y_1, ..., Y_n be fresh type variables whose bounds are as follows:

  - For all *i* (1 ≤ *i* ≤ *n*), if α_i has one or more *proper* lower bounds `L_1`, ..., `L_k`, then let the lower bound of Y_i be lub(`L_1`, ..., `L_k`); if not, then Y_i has no lower bound.
  - For all *i* (1 ≤ *i* ≤ *n*), where α_i has upper bounds U_1, ..., U_k, let the upper bound of Y_i be glb(U_1 θ, ..., U_k θ), where θ is the substitution `[`α_1:=Y_1, ..., α_n:=Y_n`]`.

  If the type variables Y_1, ..., Y_n do not have well-formed bounds (that is, a lower bound is not a subtype of an upper bound, or an intersection type is inconsistent), then resolution fails.

  Otherwise, for all *i* (1 ≤ *i* ≤ *n*), all bounds of the form G`<`..., α_i, ...`>` = capture(G`<`...`>`) are removed from the current bound set, and the bounds α_1 = Y_1, ..., α_n = Y_n are incorporated.

  If the result does not contain the bound *false*, then the result becomes the new bound set, and resolution proceeds by selecting a new set of variables to instantiate (if necessary), as described above.

  Otherwise, the result contains the bound *false*, and resolution fails.

The first method of instantiating an inference variable derives the instantiation from that variable's bounds. Sometimes, however, complex dependencies mean that the result is not within the variable's bounds. In that case, a different method of instantiation is performed, analogous to capture conversion ([§5.1.10](5.1.10.md)): fresh type variables are introduced, with bounds derived from the bounds of the inference variables. Note that the lower bounds of these "capture" variables are computed using only proper types: this is important in order to avoid attempts to perform typing computations on uninstantiated type variables.
