Java Reference
In-Depth Information
For example, if T :> List<String> and T :> List<Object> , simply intersecting the sets
ST( List<String> ) = { List<String> , Collection<String> , Object } and ST( List<Object> ) = {
List<Object> , Collection<Object> , Object } would yield a set { Object }, and we would have
lost track of the fact that T can safely be assumed to be a List .
In contrast, intersecting EST( List<String> ) = { List , Collection , Object } and EST( List<Ob-
ject> ) = { List , Collection , Object } yields { List , Collection , Object }, which we will eventu-
ally enable us to infer T = List<?> as described below.
The erased candidate set for type parameter T j , EC, is the intersection of all the sets EST( U )
for each U in U 1 ... U k .
The minimal erased candidate set for T j is:
MEC = { V | V in EC, and for all W V in EC, it is not the case that W <: V }
Because we are seeking to infer more precise types, we wish to filter out any can-
didates that are supertypes of other candidates. This is what computing MEC accom-
plishes.
In our running example, we had EC = { List , Collection , Object }, and now MEC = { List
}.
The next step will be to recover type arguments for the inferred types themselves.
For any element G of MEC that is a generic type declaration, define the relevant invoca-
tions of G , Inv(G), to be:
Inv( G ) = { V | 1 ≤ i k : V in ST( U i ), V = G < ... > }
In our running example, the only generic element of MEC is List , and Inv( List ) = {
List<String> , List<Object> }. We now will seek to find a type argument for List that con-
tains (§ 4.5.1 ) both String and Object .
This is done by means of the least containing invocation (lci) operation defined below.
The first line defines lci() on a set, such as Inv( List ), as an operation on a list of the
elements of the set. The next line defines the operation on such lists, as a pairwise re-
duction on the elements of the list. The third line is the definition of lci() on pairs of
parameterized types, which in turn relies on the notion of least containing type argu-
ment (lcta).
lcta() is defined for all six possible cases. Then CandidateInvocation( G ) defines the
most specific invocation of the generic type G that contains all the invocations of G
Search WWH ::




Custom Search