private static ResolvedReferenceType nonWildcardParameterizationOf ( ResolvedReferenceType originalType , TypeSolver typeSolver ) { List < ResolvedType > TIs = new LinkedList <> ( ) ; List < ResolvedType > AIs = originalType . typeParametersValues ( ) ; List < ResolvedTypeParameterDeclaration > TPs = originalType . getTypeDeclaration ( ) . getTypeParameters ( ) ; // Let P1...Pn be the type parameters of I with corresponding bounds B1...Bn. For all i (1 ≤ i ≤ n), // Ti is derived according to the form of Ai: ResolvedReferenceType object = new ReferenceTypeImpl ( typeSolver . solveType ( Object . class . getCanonicalName ( ) ) , typeSolver ) ; for ( int i = 0 ; i < AIs . size ( ) ; i ++ ) { ResolvedType Ai = AIs . get ( i ) ; ResolvedType Ti = null ; // - If Ai is a type, then Ti = Ai. if ( ! Ai . isWildcard ( ) ) { Ti = Ai ; } // - If Ai is a wildcard, and the corresponding type parameter's bound, Bi, mentions one of P1...Pn, then // Ti is undefined and there is no function type. if ( Ti == null && Ai . isWildcard ( ) && Ai . asWildcard ( ) . mention ( originalType . getTypeDeclaration ( ) . getTypeParameters ( ) ) ) { throw new IllegalArgumentException ( ) ; } // - Otherwise: if ( Ti == null ) { ResolvedType Bi = TPs . get ( i ) . hasLowerBound ( ) ? TPs . get ( i ) . getLowerBound ( ) : object ; // - If Ai is an unbound wildcard ?, then Ti = Bi. if ( Ai . isWildcard ( ) && ! Ai . asWildcard ( ) . isBounded ( ) ) { Ti = Bi ; } // - If Ai is a upper-bounded wildcard ? extends Ui, then Ti = glb(Ui, Bi) (§5.1.10). else if ( Ai . isWildcard ( ) && Ai . asWildcard ( ) . isUpperBounded ( ) ) { ResolvedType Ui = Ai . asWildcard ( ) . getBoundedType ( ) ; Ti = glb ( new HashSet <> ( Arrays . asList ( Ui , Bi ) ) ) ; } // - If Ai is a lower-bounded wildcard ? super Li, then Ti = Li. else if ( Ai . isWildcard ( ) && Ai . asWildcard ( ) . isLowerBounded ( ) ) { Ti = Ai . asWildcard ( ) . getBoundedType ( ) ; } else throw new RuntimeException ( "This should not happen" ) ; } TIs . add ( Ti ) ; } return new ReferenceTypeImpl ( originalType . getTypeDeclaration ( ) , TIs , typeSolver ) ; }
See JLS 9 . 9