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.
The result type is obtained by applying capture conversion (§ 5.1.10 ) to
R [ F 1 = A 1 ,..., F n = A n ] .
• Otherwise, the result type is obtained by applying capture conversion (§ 5.1.10 ) to
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
throws clause is composed of the erasure (§ 4.6 ) of the types in the method's de-
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.
The exception types that a method invocation expression can throw are specified in § 11.2.1 .
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
constructor) applicability (§ 15.12.2.2 , § 15.12.2.3 , § 15.12.2.4 ) .
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
Search WWH ::




Custom Search