@ SuppressWarnings ( "PMD.LooseCoupling" ) public static LinkedHashMap < String , Type > createGenericsMap ( final Class < ? > type , final List < ? extends Type > generics ) { final TypeVariable < ? extends Class < ? > > [ ] params = type . getTypeParameters ( ) ; if ( params . length != generics . size ( ) ) { throw new IllegalArgumentException ( String . format ( "Can't build generics map for %s with %s because of incorrect generics count" , type . getSimpleName ( ) , Arrays . toString ( generics . toArray ( ) ) ) ) ; } final LinkedHashMap < String , Type > res = new LinkedHashMap < String , Type > ( ) ; int i = 0 ; for ( TypeVariable var : params ) { res . put ( var . getName ( ) , generics . get ( i ++ ) ) ; } // add possible outer class generics to avoid unknown generics return GenericsResolutionUtils . fillOuterGenerics ( type , res , null ) ; }
LinkedHashMap indicates stored order important for context