Replaces type variables of the given
formal type
with the types they stand for in the given
actual type.
A ParameterizedType is a class with type parameters, and the values
of those parameters. For example, Map<K,V> is a generic class, and
a corresponding ParameterizedType might look like
Map<K=String,V=Integer>. Given such a ParameterizedType, this method
will replace K with String, or List<K> with List<String;, or
List<? super K> with List<? super String>.
The
actual argument to this method can also be a Class.
In this case, either it is equivalent to a ParameterizedType with
no parameters (for example, Integer.class), or it is equivalent to
a "raw" ParameterizedType (for example, Map.class). In the latter
case, every type parameter declared or inherited by the class is replaced
by its "erasure". For a type parameter declared as <T>, the erasure
is Object. For a type parameter declared as <T extends Number>,
the erasure is Number.
Although type parameters are not inherited by subclasses in the Java
language, they are effectively inherited when using reflection.
For example, if you declare an interface like this...
public interface StringToIntMap extends Map<String,Integer> {}
...then StringToIntMap.class.getMethods() will show that it has methods
like put(K,V) even though StringToIntMap has no type parameters. The K
and V variables are the ones declared by Map, so
TypeVariable.getGenericDeclaration will return
Map Map.class .
For this reason, this method replaces inherited type parameters too.
Therefore if this method is called with
actual being
StringToIntMap.class and
formal being the K from Map,
it will return
String String.class .
In the case where
actual is a "raw" ParameterizedType, the
inherited type parameters will also be replaced by their erasures.
The erasure of a Class is the Class itself, so a "raw" subinterface of
StringToIntMap will still show the K from Map as String.class. But
in a case like this...
public interface StringToIntListMap extends Map<String,List<Integer>> {}
public interface RawStringToIntListMap extends StringToIntListMap {}
...the V inherited from Map will show up as List<Integer> in
StringToIntListMap, but as plain List in RawStringToIntListMap.
Parameters: actual - the type that supplies bindings for type variables Parameters: formal - the type where occurrences of the variablesin actual will be replaced by the corresponding bound values a resolved type See Also: TypeResolver.TypeResolver(Type) See Also: TypeResolver.resolve(Type) |