where and types are resolved using resolveType.
Note that usually type mappings are already implied by the static type hierarchy (for example,
the E type variable declared by class List naturally maps to String in
the context of class MyStringList implements List<String>). In such case, prefer to use
TypeToken#resolveType since it's simpler and more type safe. This class should only be
used when the type mapping isn't implied by the static type hierarchy, but provided through other
means such as an annotation or external configuration file.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private static class | TypeResolver.TypeTable
A TypeTable maintains mapping from |
| pack-priv static class | TypeResolver.TypeVariableKey
Wraps around |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final TypeResolver. |
| Access | Constructor and Description |
|---|---|
| public | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv static TypeResolver | |
| private static <T> T | |
| pack-priv static TypeResolver | |
| private static void | |
| private Type | |
| private ParameterizedType | |
| public Type | resolveType(Type type)
Resolves all type variables in |
| private Type[] | |
| pack-priv Type[] | |
| private WildcardType | |
| public TypeResolver | where(Type
The type whose type variables or itself is mapped to other type(s). It's almost
always a bug if formal, Type formal isn't a type variable and contains no type variable. Make
sure you are passing the two parameters in the right order.The type that the formal type variable(s) are mapped to. It can be or contain yet
other type variables, in which case these type variables will be further resolved if
corresponding mappings exist in the current actual)TypeResolver instance.Returns a new |
| pack-priv TypeResolver | where(Map<TypeResolver.
Returns a new |
| typeTable | back to summary |
|---|---|
| private final TypeResolver. | |
| TypeResolver | back to summary |
|---|---|
| public TypeResolver() | |
| TypeResolver | back to summary |
|---|---|
| private TypeResolver(TypeResolver. | |
| covariantly | back to summary |
|---|---|
| pack-priv static TypeResolver covariantly(Type contextType) Returns a resolver that resolves types "covariantly". For example, when resolving | |
| expectArgument | back to summary |
|---|---|
| private static <T> T expectArgument(Class<T> type, Object arg) | |
| invariantly | back to summary |
|---|---|
| pack-priv static TypeResolver invariantly(Type contextType) Returns a resolver that resolves types "invariantly". For example, when resolving Instead, | |
| populateTypeMappings | back to summary |
|---|---|
| private static void populateTypeMappings(Map<TypeResolver. | |
| resolveGenericArrayType | back to summary |
|---|---|
| private Type resolveGenericArrayType(GenericArrayType type) | |
| resolveParameterizedType | back to summary |
|---|---|
| private ParameterizedType resolveParameterizedType(ParameterizedType type) | |
| resolveType | back to summary |
|---|---|
| public Type resolveType(Type type) Resolves all type variables in | |
| resolveTypes | back to summary |
|---|---|
| private Type[] resolveTypes(Type[] types) | |
| resolveTypesInPlace | back to summary |
|---|---|
| pack-priv Type[] resolveTypesInPlace(Type[] types) | |
| resolveWildcardType | back to summary |
|---|---|
| private WildcardType resolveWildcardType(WildcardType type) | |
| where | back to summary |
|---|---|
| public TypeResolver where(Type formal, Type actual) Returns a new For example, if
| |
| where | back to summary |
|---|---|
| pack-priv TypeResolver where(Map<TypeResolver. Returns a new | |
| Modifier and Type | Field and Description |
|---|---|
| private final Map |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv static ImmutableMap | getTypeMappings(Type contextType)
Returns type mappings using type parameters and type arguments found in the generic
superclass and the super interfaces of |
| private void | |
| pack-priv void | |
| pack-priv void | visitParameterizedType(ParameterizedType parameterizedType)
Overrides com. |
| pack-priv void | |
| pack-priv void |
| mappings | back to summary |
|---|---|
| private final Map<TypeResolver. | |
| TypeMappingIntrospector | back to summary |
|---|---|
| private TypeMappingIntrospector() | |
| getTypeMappings | back to summary |
|---|---|
| pack-priv static ImmutableMap Returns type mappings using type parameters and type arguments found in the generic
superclass and the super interfaces of | |
| map | back to summary |
|---|---|
| private void map(TypeResolver. | |
| visitClass | back to summary |
|---|---|
| pack-priv void visitClass(Class<?> clazz) Overrides com.
| |
| visitParameterizedType | back to summary |
|---|---|
| pack-priv void visitParameterizedType(ParameterizedType parameterizedType) Overrides com.
| |
| visitTypeVariable | back to summary |
|---|---|
| pack-priv void visitTypeVariable(TypeVariable<?> t) Overrides com.
| |
| visitWildcardType | back to summary |
|---|---|
| pack-priv void visitWildcardType(WildcardType t) Overrides com.
| |
TypeVariable to types.
| Modifier and Type | Field and Description |
|---|---|
| private final ImmutableMap |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv final Type | |
| pack-priv Type | resolveInternal(TypeVariable<?> var, TypeResolver.
Resolves |
| pack-priv final TypeResolver. | where(Map<TypeResolver.
Returns a new |
| map | back to summary |
|---|---|
| private final ImmutableMap<TypeResolver. | |
| TypeTable | back to summary |
|---|---|
| pack-priv TypeTable() | |
| TypeTable | back to summary |
|---|---|
| private TypeTable(ImmutableMap<TypeResolver. | |
| resolve | back to summary |
|---|---|
| pack-priv final Type resolve(TypeVariable<?> var) | |
| resolveInternal | back to summary |
|---|---|
| pack-priv Type resolveInternal(TypeVariable<?> var, TypeResolver. Resolves Should only be called and overridden by | |
| where | back to summary |
|---|---|
| pack-priv final TypeResolver. Returns a new | |
TypeVariable<?> to ensure that any two type variables are equal as long as
they are declared by the same java.lang.reflect.GenericDeclaration and have the same
name, even if their bounds differ.
While resolving a type variable from a var -> type map, we don't care whether the
type variable's bound has been partially resolved. As long as the type variable "identity"
matches.
On the other hand, if for example we are resolving List<A extends B> to List<A extends String>, we need to compare that <A extends B> is unequal to <A
extends String> in order to decide to use the transformed type instead of the original type.
| Modifier and Type | Field and Description |
|---|---|
| private final TypeVariable |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | equals(Object
the reference object with which to compare. obj)Overrides java. |
| pack-priv boolean | equalsType(Type type)
Returns true if |
| private boolean | |
| pack-priv static TypeResolver. | |
| public int | |
| public String |
| var | back to summary |
|---|---|
| private final TypeVariable<?> var | |
| TypeVariableKey | back to summary |
|---|---|
| pack-priv TypeVariableKey(TypeVariable<?> var) | |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| equalsType | back to summary |
|---|---|
| pack-priv boolean equalsType(Type type) Returns true if | |
| equalsTypeVariable | back to summary |
|---|---|
| private boolean equalsTypeVariable(TypeVariable<?> that) | |
| forLookup | back to summary |
|---|---|
| pack-priv static TypeResolver. Wraps
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object. | |
| Modifier and Type | Field and Description |
|---|---|
| private final AtomicInteger | |
| pack-priv static final TypeResolver. |
| Access | Constructor and Description |
|---|---|
| private | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv final Type | |
| pack-priv TypeVariable | |
| private Type | |
| private TypeResolver. | |
| private TypeResolver. |
| id | back to summary |
|---|---|
| private final AtomicInteger id | |
| INSTANCE | back to summary |
|---|---|
| pack-priv static final TypeResolver. | |
| WildcardCapturer | back to summary |
|---|---|
| private WildcardCapturer() | |
| WildcardCapturer | back to summary |
|---|---|
| private WildcardCapturer(AtomicInteger id) | |
| capture | back to summary |
|---|---|
| pack-priv final Type capture(Type type) | |
| captureAsTypeVariable | back to summary |
|---|---|
| pack-priv TypeVariable | |
| captureNullable | back to summary |
|---|---|
private Type captureNullable(Type type)
| |
| forTypeVariable | back to summary |
|---|---|
| private TypeResolver. | |
| notForTypeVariable | back to summary |
|---|---|
| private TypeResolver. | |