Java Reference
In-Depth Information
as arguments to library methods that use parameterized versions of those same types
as the types of their corresponding formal parameters.
Such calls cannot be shown to be statically safe under the type system using generics.
Rejecting such calls would invalidate large bodies of existing code, and prevent them
from using newer versions of the libraries. This in turn, would discourage library
vendors from taking advantage of genericity. To prevent such an unwelcome turn of
events, a raw type may be converted to an arbitrary invocation of the generic type de-
claration to which the raw type refers. While the conversion is unsound, it is tolerated
as a concession to practicality. An unchecked warning is issued in such cases.
5.1.10. Capture Conversion
Let G name a generic type declaration (§ 8.1.2 , § 9.1.2 ) with n type parameters A 1 ,..., A n with
corresponding bounds U 1 ,..., U n .
There exists a capture conversion from a parameterized type G < T 1 ,..., T n > 4.5 ) to a para-
meterized type G < S 1 ,..., S n > , where, for 1 ≤ i n :
• If T i is a wildcard type argument (§ 4.5.1 ) of the form ? , then S i is a fresh type vari-
able whose upper bound is U i [ A 1 := S 1 ,..., A n := S n ] and whose lower bound is the null
type (§ 4.1 ).
• If T i is a wildcard type argument of the form ? extends B i , then S i is a fresh type vari-
able whose upper bound is glb( B i , U i [ A 1 := S 1 ,..., A n := S n ] ) and whose lower bound is
the null type.
glb( V 1 ,..., V m ) is defined as V 1 & ... & V m .
It is a compile-time error if, for any two classes (not interfaces) V i and V j , V i is not
a subclass of V j or vice versa.
• If T i is a wildcard type argument of the form ? super B i , then S i is a fresh type vari-
able whose upper bound is U i [ A 1 := S 1 ,..., A n := S n ] and whose lower bound is B i .
• Otherwise, S i = T i .
Capture conversion on any type other than a parameterized type (§ 4.5 ) acts as an identity
conversion (§ 5.1.1 ).
Capture conversion is not applied recursively.
Capture conversion never requires a special action at run time and therefore never throws
an exception at run time.
Search WWH ::




Custom Search