java.lang.Object | |
↳ | com.sun.beans.TypeResolver |
This is utility class to resolve types.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Converts all
types in the given array
to the corresponding classes. | |||||||||||
Converts the given
type to the corresponding class. | |||||||||||
Replaces type variables of the given
formal type
with the types they stand for in the given actual type. | |||||||||||
Replaces type variables of all formal types in the given array
with the types they stand for in the given
actual type. | |||||||||||
Replaces the given
type in an inherited method
with the actual type it has in the given inClass . | |||||||||||
Replaces all
types in the given array
with the actual types they have in the given inClass . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Converts all types
in the given array
to the corresponding classes.
types | the array of types to convert |
---|
Converts the given type
to the corresponding class.
This method implements the concept of type erasure,
that is described in section 4.6
of Java Language Specification.
type | the array of types to convert |
---|
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
getGenericDeclaration()
will return 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.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.
actual | the type that supplies bindings for type variables |
---|---|
formal | the type where occurrences of the variables
in actual will be replaced by the corresponding bound values |
Replaces type variables of all formal types in the given array
with the types they stand for in the given actual
type.
actual | the type that supplies bindings for type variables |
---|---|
formals | the array of types to resolve |
Replaces the given type
in an inherited method
with the actual type it has in the given inClass
.
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
getGenericDeclaration()
will return Map.class.
The purpose of this method is to take a Type from a possibly-inherited method and replace it with the correct Type for the inheriting class. So given parameters of K and StringToIntMap.class in the above example, this method will return String.
inClass | the base class used to resolve |
---|---|
type | the type to resolve |
resolve(Type, Type)
Replaces all types
in the given array
with the actual types they have in the given inClass
.
inClass | the base class used to resolve |
---|---|
types | the array of types to resolve |
resolve(Type, Type[])