JVM Knowledge

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), 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, if S and T are intersection types, a correspondence between the elements of S and the elements of T is established. An element of S, S_i, corresponds to an element of T, T_j, if S_i and T_j are either the same type, or both parameterizations of the same generic class or interface, or both array types.

    If each element of S corresponds to exactly one element of T, and vice versa, then the constraint reduces to the following new constraints: for each element S_i of S and the corresponding element T_j of T, ‹S_i = T_j›. If not, the constraint reduces to false.

    This rule does not accommodate inference variables appearing directly as elements of an intersection type (rather than nested in a parameterized type). Due to the restrictions on type parameter declarations (§4.4), such intersection types do not arise in practice.

  • Otherwise, the constraint reduces to false.

A constraint formula of the form ‹S = T›, where S and T are type arguments (§4.5.1), 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.