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 ,
♦ for any constraint of the form V >> T i generated in § 15.12.2.7 : a constraint
V [ T 1 =B( T 1 ) ... T n =B( T n )] >> T i .
♦ for any constraint of the form T i = V generated in § 15.12.2.7 : a constraint 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
§ 15.12.2.7 .
Any equality constraints are resolved, and then, for each remaining constraint of the
form T i <: U k , the argument T i is inferred to be glb( U 1 , ..., U k ) (§ 5.1.10 ).
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 .
Search WWH ::




Custom Search