T - is the generic type of the retrieval class.public interface GenericType<T> extends Type
Type (available via getType()) but allows easy access to resolve the actual erasure
Class for assignment and retrieval. This includes
resolving TypeVariables as far as possible.
public class Foo<A, B> {
A getA() { ... }
B getB() { ... }
}
public class Bar<X> extends Foo<X, String> {
...
}
public class Some extends Bar<Long> {
...
}
If you want to determine the type of Some.getA() reflectively, you will have to dive into the deepest and
trickiest part of the reflection API and might step into one of the many pitfalls on this way. All this is solved for
you, if you use what is offered via this API. GenericTypeFactory.createGenericType(Type),
GenericTypeFactory.createGenericType(Type, GenericType)| Modifier and Type | Field and Description |
|---|---|
static GenericType<?>[] |
NO_TYPES
An empty
GenericType-array. |
| Modifier and Type | Method and Description |
|---|---|
Class<? extends T> |
getAssignmentClass()
This method gets the
Class to be used for assignment (as parameter) of a value of this GenericType. |
GenericType<?> |
getComponentType()
This method gets the component-type of this
GenericType if it represents an array,
Collection or Map. |
GenericType<?> |
getKeyType()
This method gets the key-type of this
GenericType if it represents a Map. |
Class<T> |
getRetrievalClass()
This method gets the
Class to be used for retrieval (the return-type) of a value of this
GenericType. |
Type |
getType()
This method gets the
Type represented by this GenericType. |
GenericType<?> |
getTypeArgument(int index)
This method gets the type-argument at the given
index. |
int |
getTypeArgumentCount()
This method gets the number of
type-arguments . |
boolean |
isAssignableFrom(GenericType<?> subType)
This method determines if this
GenericType is equal to or a super-type of the given subType. |
boolean |
isCollection() |
boolean |
isMap() |
String |
toString()
This method gets the string representation of this
GenericType. |
String |
toStringSimple() |
getTypeNamestatic final GenericType<?>[] NO_TYPES
GenericType-array.Class<? extends T> getAssignmentClass()
Class to be used for assignment (as parameter) of a value of this GenericType.
retrieval-class if this GenericType is a
WildcardType. lower-bound, the assignment-class is never
null. If there is no lower-bound, the
assignment-class is the same as the retrieval-class.
Therefore the assignment-class is always equal or more specific to the
retrieval-class. | Type | getAssignmentClass() |
|---|---|
| <? super Integer> | Integer |
| <? extends CharSequence> | CharSequence |
String |
String |
Class that is the lower bound.Class<T> getRetrievalClass()
Class to be used for retrieval (the return-type) of a value of this
GenericType. assignment-class if this GenericType is a
WildcardType. retrieval-class is the upper-bound, however for usability and simplicity only one bound is supported. | Type | getAssignmentClass() |
|---|---|
| <? super Integer> | Object |
| <? extends CharSequence> | CharSequence |
String |
String |
Class that is the upper bound.Type getType()
Type represented by this GenericType.Class.getGenericSuperclass(),
Class.getGenericInterfaces(),
Method.getGenericReturnType(),
Method.getGenericParameterTypes(),
Field.getGenericType(),
Constructor.getGenericParameterTypes()GenericType<?> getComponentType()
GenericType if it represents an array,
Collection or Map. | type | getComponentType() |
|---|---|
| List<Map<String, Long>> | Map<String, Long> |
List |
Object |
Foo[] |
Foo |
| Foo<Bar>[] | Foo<Bar> |
| Foo<Bar> | null |
| Map<String, Long> | Long |
GenericType or null if this GenericType does NOT
represent an array, Collection or Map.GenericType<?> getKeyType()
GenericType if it represents a Map. | type | getComponentType() |
|---|---|
| List<Map<String, Long>> | null |
Map |
Object |
Foo[] |
null |
| Foo<K,V> | null |
| Map<String, Long> | String |
| HashMap<? extends Number, Long> | ? extends Number |
GenericType or null if this GenericType does NOT represent a
Map.int getTypeArgumentCount()
type-arguments .GenericType<?> getTypeArgument(int index)
index. GenericType representing Map<String, List<Integer>> this method would return
String for an index of 0 and List<Integer> for an index of 1.index - is the position of the requested type-argument. It has to be in the range from 0 to
getTypeArgumentCount() - 1.index.getTypeArgumentCount(),
ParameterizedType.getActualTypeArguments()boolean isAssignableFrom(GenericType<?> subType)
GenericType is equal to or a super-type of the given subType. X.isAssignableFrom(Y) is true, then an instance of Y can be casted to X. subType - is the potential sub-type of this GenericType.true if objects of the type subType can be assigned to this GenericType.Class.isAssignableFrom(Class)boolean isCollection()
true if this GenericType represents a Collection.boolean isMap()
true if this GenericType represents a Map.String toString()
GenericType. In case the underlying value-type is a regular Class, this method will return its qualified name
otherwise it will return the string representation of the generic type information (e.g.
java.util.Map<java.lang.String, java.util.List<java.lang.Integer>>[]).toString in class ObjectGenericType as string.String toStringSimple()
simple names for Classes.ReflectionUtil.toStringSimple(Type)Copyright © 2001–2019 mmm-Team. All rights reserved.