TypeUtils { private static Map<TypeVariable<?>, Type> getTypeArguments(final ParameterizedType type) { return getTypeArguments(type, getRawType(type), null); } private  TypeUtils(); static boolean isAssignable(final Type type, final Type toType); static Type[] normalizeUpperBounds(final Type[] bounds); static boolean equals(final Type t1, final Type t2); static String toString(final Type type); static int[] add(int[] array, int element);  }
@SuppressWarnings("UnusedAssignment") @Test public void testGetTypeArguments() { Map<TypeVariable<?>, Type> typeVarAssigns; TypeVariable<?> treeSetTypeVar; Type typeArg; typeVarAssigns = TypeUtils.getTypeArguments(Integer.class, Comparable.class); treeSetTypeVar = Comparable.class.getTypeParameters()[0]; assertTrue(typeVarAssigns.containsKey(treeSetTypeVar)); typeArg = typeVarAssigns.get(treeSetTypeVar); assertEquals(Integer.class, typeVarAssigns.get(treeSetTypeVar)); typeVarAssigns = TypeUtils.getTypeArguments(int.class, Comparable.class); treeSetTypeVar = Comparable.class.getTypeParameters()[0]; assertTrue(typeVarAssigns.containsKey(treeSetTypeVar)); typeArg = typeVarAssigns.get(treeSetTypeVar); assertEquals(Integer.class, typeVarAssigns.get(treeSetTypeVar)); @SuppressWarnings("ArraysAsListWithZeroOrOneArgument") final Collection<Integer> col = Arrays.asList(new Integer[0]); typeVarAssigns = TypeUtils.getTypeArguments(List.class, Collection.class); treeSetTypeVar = Comparable.class.getTypeParameters()[0]; assertFalse(typeVarAssigns.containsKey(treeSetTypeVar)); typeVarAssigns = TypeUtils.getTypeArguments(AAAClass.BBBClass.class, AAClass.BBClass.class); assertEquals(2, typeVarAssigns.size()); assertEquals(String.class, typeVarAssigns.get(AAClass.class.getTypeParameters()[0])); assertEquals(String.class, typeVarAssigns.get(AAClass.BBClass.class.getTypeParameters()[0])); typeVarAssigns = TypeUtils.getTypeArguments(Other.class, This.class); assertEquals(2, typeVarAssigns.size()); assertEquals(String.class, typeVarAssigns.get(This.class.getTypeParameters()[0])); assertEquals(Other.class.getTypeParameters()[0], typeVarAssigns.get(This.class.getTypeParameters()[1])); typeVarAssigns = TypeUtils.getTypeArguments(And.class, This.class); assertEquals(2, typeVarAssigns.size()); assertEquals(Number.class, typeVarAssigns.get(This.class.getTypeParameters()[0])); assertEquals(Number.class, typeVarAssigns.get(This.class.getTypeParameters()[1])); typeVarAssigns = TypeUtils.getTypeArguments(Thing.class, Other.class); assertEquals(2, typeVarAssigns.size()); assertEquals(getClass().getTypeParameters()[0], typeVarAssigns.get(getClass().getTypeParameters()[0])); assertEquals(getClass().getTypeParameters()[0], typeVarAssigns.get(Other.class.getTypeParameters()[0])); }