Java Reference
In-Depth Information
15.12.2.8. Inferring Unresolved Type Arguments
If any of the method's type arguments were not inferred from the types of the actual argu-
ments, they are now inferred as follows.
• If the method result occurs in a context where it will be subject to assignment con-
version (§
5.2
) to a type
S
, then let
R
be the declared result type of the method, and
let
R
' =
R
[
T
1
=B(
T
1
) ...
T
n
=B(
T
n
)
]
, where B(
T
i
) is the type inferred for
T
i
in the previ-
ous section or
T
i
if no type was inferred.
If
S
is a reference type, then let
S
' be
S
. Otherwise, if
S
is a primitive type, then let
S
' be the result of applying boxing conversion (§
5.1.7
) to
S
.
Then, a set of initial constraints consisting of:
♦ the constraint
S
' >>
R
', provided
R
is not
void
; and
♦ additional constraints
B
i
[
T
1
=B(
T
1
) ...
T
n
=B(
T
n
)
]
>>
T
i
, where
B
i
is the declared
bound of
T
i
,
♦ additional constraints B(
T
i
) <<
B
i
[
T
1
=B(
T
1
) ...
T
n
=B(
T
n
)], where
B
i
is the de-
clared bound of
T
i
,
V
[
T
1
=B(
T
1
) ...
T
n
=B(
T
n
)] >>
T
i
.
V
[
T
1
=B(
T
1
) ...
T
n
=B(
T
n
)].
is created and used to infer constraints on the type arguments using the algorithm of
Any equality constraints are resolved, and then, for each remaining constraint of the
If
T
i
appears as a type argument in any
U
k
, then
T
i
is inferred to be a type variable
X
whose upper bound is the parameterized type given by glb(
U
1
[
T
i
=
X
], ...,
U
k
[
T
i
=
X
])
and whose lower bound is the null type.
Any remaining type variable
T
that has not yet been inferred is then inferred to have
type
Object
. If a previously inferred type variable
P
uses
T
, then
P
is inferred to be
P
[
T
=
Object
].
• Otherwise, the unresolved type arguments are inferred by invoking the procedure
described in this section under the assumption that the method result was assigned
to a variable of type
Object
.