Java Reference
In-Depth Information
• Otherwise, if the chosen method is generic, then for 1 ≤
i
≤
n
, let
F
i
be the formal
type parameters of the method, let
A
i
be the actual type arguments inferred for the
method invocation, and let
R
be the return type of the chosen method.
R
[
F
1
=
A
1
,...,
F
n
=
A
n
]
.
the return type of the chosen method .
The exception types of the
throws
clause of the chosen method are determined as follows:
• If unchecked conversion was necessary for the method to be applicable, then the
clared
throws
clause.
• Otherwise, if the method being invoked is generic, then for 1 ≤
i
≤
n
, let
F
i
be the
type parameters of the method, let
A
i
be the type arguments inferred for the method
invocation, and let
E
j
(1 ≤
j
≤
m
) be the exception types declared in the
throws
clause of the method being invoked.
The
throws
clause consists of the types
E
j
[
F
1
=
A
1
,...,
F
n
=
A
n
]
.
• Otherwise, the type of the
throws
clause is the type given in the method declaration.
15.12.2.7. Inferring Type Arguments Based on Actual Arguments
In this section, we describe the process of inferring type arguments for method and con-
structor invocations. This process is invoked as a subroutine when testing for method (or
The process of type inference is inherently complex. Therefore, it is useful to give an
informal overview of the process before delving into the detailed specification.
Inference begins with an initial set of constraints. Generally, the constraints require
that the statically known types of the actual arguments are acceptable given the de-
clared formal parameter types. We discuss the meaning of “acceptable” below.
Given these initial constraints, one may derive a set of supertype and/or equality con-
straints on the type parameters of the method or constructor.
Next, one must try and find a solution that satisfies the constraints on the type para-
meters. As a first approximation, if a type parameter is constrained by an equality
constraint, then that constraint gives its solution. Bear in mind that the constraint may