类 ResolvableType
- 所有已实现的接口:
Serializable
Type, providing access to
supertypes, interfaces, and
generic parameters along with the ability to ultimately
resolve to a Class.
ResolvableTypes may be obtained from fields,
executable parameters,
method returns or
classes. Most methods on this class will themselves return
ResolvableTypes, allowing easy navigation. For example:
private HashMap<Integer, List<String>> myMap;
public void example() {
ResolvableType t = ResolvableType.fromField(getClass().getDeclaredField("myMap"));
t.getSuperType(); // AbstractMap<Integer, List<String>>
t.asMap(); // Map<Integer, List<String>>
t.getGeneric(0).resolve(); // Integer
t.getGeneric(1).resolve(); // List
t.getGeneric(1); // List<String>
t.resolveGeneric(1, 0); // String
}
From Spring
- 从以下版本开始:
- 3.0
- 作者:
- Phillip Webb, Juergen Hoeller, Stephane Nicoll
- 另请参阅:
-
嵌套类概要
嵌套类 -
字段概要
字段修饰符和类型字段说明static final ResolvableType[]static final ResolvableTypeResolvableTypereturned when no value is available. -
方法概要
修饰符和类型方法说明Return this type as aResolvableTypeof the specified class.Convenience method to return this type as a resolvableCollectiontype.asMap()Convenience method to return this type as a resolvableMaptype.static voidClear the internalResolvableType/SerializableTypeWrappercache.booleanstatic ResolvableTypeforMethodParameter(MethodParameter methodParameter) Return aResolvableTypefor the specifiedMethodParameter.static ResolvableTypeforMethodParameter(MethodParameter methodParameter, ResolvableType implementationType) Return aResolvableTypefor the specifiedMethodParameterwith a given implementation type.static ResolvableTypeforMethodParameter(MethodParameter methodParameter, Type targetType) Return aResolvableTypefor the specifiedMethodParameter, overriding the target type to resolve with a specific given type.static ResolvableTypeforMethodParameter(MethodParameter methodParameter, Type targetType, int nestingLevel) Return aResolvableTypefor the specifiedMethodParameterat a specific nesting level, overriding the target type to resolve with a specific given type.static ResolvableTypeforParameter(Executable executable, int parameterIndex) Return aResolvableTypefor the specifiedExecutableparameter.static ResolvableTypeforParameter(Executable executable, int parameterIndex, Class<?> implementationClass) Return aResolvableTypefor the specifiedMethodparameter with a given implementation.static ResolvableTypeforReturnType(Method method) Return aResolvableTypefor the specifiedMethodreturn type.static ResolvableTypeforReturnType(Method method, Class<?> implementationClass) Return aResolvableTypefor the specifiedMethodreturn type.static ResolvableTypefromArrayComponent(ResolvableType componentType) Return aResolvableTypeas a array of the specifiedcomponentType.static ResolvableTypeReturn aResolvableTypefor the specifiedClass, using the full generic type information for assignability checks.static ResolvableTypeReturn aResolvableTypefor the specified base type (interface or base class) with a given implementation class.static ResolvableTypefromClassWithGenerics(Class<?> clazz, ResolvableType... generics) Return aResolvableTypefor the specifiedClasswith pre-declared generics.static ResolvableTypefromClassWithGenerics(Class<?> clazz, Class<?>... generics) Return aResolvableTypefor the specifiedClasswith pre-declared generics.static ResolvableTypeReturn aResolvableTypefor the specifiedField.static ResolvableTypeReturn aResolvableTypefor the specifiedFieldwith the given nesting level.static ResolvableTypeReturn aResolvableTypefor the specifiedFieldwith a given implementation and the given nesting level.static ResolvableTypefromField(Field field, ResolvableType implementationType) Return aResolvableTypefor the specifiedFieldwith a given implementation.static ResolvableTypeReturn aResolvableTypefor the specifiedFieldwith a given implementation.static ResolvableTypefromInstance(Object instance) Return aResolvableTypefor the specified instance.static ResolvableTypefromParameter(Parameter parameter) Return aResolvableTypefor the specifiedParameter.static ResolvableTypefromParameter(Parameter parameter, ResolvableType implementationType) Return aResolvableTypefor the specifiedParameterwith a given implementation type.static ResolvableTypefromParameter(Parameter parameter, Class<?> implementationType) static ResolvableTypefromParameter(Parameter parameter, Type targetType) Return aResolvableTypefor the specifiedParameter, overriding the target type to resolve with a specific given type.static ResolvableTypefromRawClass(Class<?> clazz) Return aResolvableTypefor the specifiedClass, doing assignability checks against the raw class only (analogous toClass.isAssignableFrom(java.lang.Class<?>), which this serves as a wrapper for.static ResolvableTypefromType(TypeReference<?> typeReference) Return aResolvableTypefor the specifiedTypeReference.static ResolvableTypeReturn aResolvableTypefor the specifiedType.static ResolvableTypefromType(Type type, ResolvableType owner) Return aResolvableTypefor the specifiedTypebacked by the given owner type.Return the ResolvableType representing the component type of the array orNONEif this type does not represent an array.getGeneric(int... indexes) Return aResolvableTyperepresenting the generic parameter for the given indexes.Return an array ofResolvableTypesrepresenting the generic parameters of this type.Return aResolvableTypearray representing the direct interfaces implemented by this type.getNested(int nestingLevel) Return aResolvableTypefor the specified nesting level.Return aResolvableTypefor the specified nesting level.Class<?>Return the underlying JavaClassbeing managed, if available; otherwisenull.Return the underlying source of the resolvable type.Return aResolvableTyperepresenting the direct supertype of this type.getType()Return the underling JavaTypebeing managed.booleanReturntrueif this type contains generic parameters.inthashCode()booleanDetermine whether the underlying type has any unresolvable generics: either through an unresolvable type variable on the type itself or through implementing a generic interface in a raw fashion, i.e. without substituting that interface's type variables.booleanbooleanisArray()Returntrueif this type resolves to a Class that represents an array.booleanisAssignableFrom(ResolvableType other) Determine whether thisResolvableTypeis assignable from the specified other type.booleanisAssignableFrom(Class<?> other) Determine whether thisResolvableTypeis assignable from the specified other type.booleanbooleanisInstance(Object obj) Determine whether the given object is an instance of thisResolvableType.booleanisMap()Is this type aMaptype?Class<?>resolve()Resolve this type to aClass, returningnullif the type cannot be resolved.Class<?>Resolve this type to aClass, returning the specifiedfallbackif the type cannot be resolved.Class<?>resolveGeneric(int... indexes) Class<?>[]Class<?>[]resolveGenerics(Class<?> fallback) Class<?>toClass()Return this type as a resolvedClass, falling back toObjectif no specific class can be resolved.toString()Return a String representation of this type in its fully resolved form (including any generic parameters).static ResolvableTypevalueOf(Type type, ResolvableType.VariableResolver variableResolver) static ResolvableTypevalueOf(Type type, cn.taketoday.core.SerializableTypeWrapper.TypeProvider typeProvider, ResolvableType.VariableResolver variableResolver)
-
字段详细资料
-
NONE
ResolvableTypereturned when no value is available.NONEis used in preference tonullso that multiple method calls can be safely chained. -
EMPTY_TYPES_ARRAY
-
-
方法详细资料
-
getType
Return the underling JavaTypebeing managed. -
getRawClass
Return the underlying JavaClassbeing managed, if available; otherwisenull. -
getSource
Return the underlying source of the resolvable type. Will return aField,MethodParameterorTypedepending on how theResolvableTypewas constructed. This method is primarily to provide access to additional type information or meta-data that alternative JVM languages may provide. -
toClass
Return this type as a resolvedClass, falling back toObjectif no specific class can be resolved.- 返回:
- the resolved
Classor theObjectfallback - 另请参阅:
-
isInstance
Determine whether the given object is an instance of thisResolvableType.- 参数:
obj- the object to check- 另请参阅:
-
isAssignableFrom
Determine whether thisResolvableTypeis assignable from the specified other type.- 参数:
other- the type to be checked against (as aClass)- 另请参阅:
-
isAssignableFrom
Determine whether thisResolvableTypeis assignable from the specified other type.Attempts to follow the same rules as the Java compiler, considering whether both the
resolvedClassisassignable fromthe given type as well as whether allgenericsare assignable.- 参数:
other- the type to be checked against (as aResolvableType)- 返回:
trueif the specified other type can be assigned to thisResolvableType;falseotherwise
-
isArray
public boolean isArray()Returntrueif this type resolves to a Class that represents an array.- 另请参阅:
-
getComponentType
Return the ResolvableType representing the component type of the array orNONEif this type does not represent an array.- 另请参阅:
-
asCollection
Convenience method to return this type as a resolvableCollectiontype. ReturnsNONEif this type does not implement or extendCollection. -
asMap
Convenience method to return this type as a resolvableMaptype. ReturnsNONEif this type does not implement or extendMap.- 另请参阅:
-
as
Return this type as aResolvableTypeof the specified class. Searchessupertypeandinterfacehierarchies to find a match, returningNONEif this type does not implement or extend the specified class.- 参数:
type- the required type (typically narrowed)- 返回:
- a
ResolvableTyperepresenting this object as the specified type, orNONEif not resolvable as that type - 另请参阅:
-
getSuperType
Return aResolvableTyperepresenting the direct supertype of this type. If no supertype is available this method returnsNONE.Note: The resulting
ResolvableTypeinstance may not beSerializable.- 另请参阅:
-
getInterfaces
Return aResolvableTypearray representing the direct interfaces implemented by this type. If this type does not implement any interfaces an empty array is returned.Note: The resulting
ResolvableTypeinstances may not beSerializable.- 另请参阅:
-
hasGenerics
public boolean hasGenerics()Returntrueif this type contains generic parameters. -
hasUnresolvableGenerics
public boolean hasUnresolvableGenerics()Determine whether the underlying type has any unresolvable generics: either through an unresolvable type variable on the type itself or through implementing a generic interface in a raw fashion, i.e. without substituting that interface's type variables. The result will betrueonly in those two scenarios. -
getNested
Return aResolvableTypefor the specified nesting level. SeegetNested(int, Map)for details.- 参数:
nestingLevel- the nesting level- 返回:
- the
ResolvableTypetype, or#NONE
-
getNested
public ResolvableType getNested(int nestingLevel, @Nullable Map<Integer, Integer> typeIndexesPerLevel) Return aResolvableTypefor the specified nesting level.The nesting level refers to the specific generic parameter that should be returned. A nesting level of 1 indicates this type; 2 indicates the first nested generic; 3 the second; and so on. For example, given
List<Set<Integer>>level 1 refers to theList, level 2 theSet, and level 3 theInteger.The
typeIndexesPerLevelmap can be used to reference a specific generic for the given level. For example, an index of 0 would refer to aMapkey; whereas, 1 would refer to the value. If the map does not contain a value for a specific level the last generic will be used (e.g. aMapvalue).Nesting levels may also apply to array types; for example given
String[], a nesting level of 2 refers toString.If a type does not
containgenerics thesupertypehierarchy will be considered.- 参数:
nestingLevel- the required nesting level, indexed from 1 for the current type, 2 for the first nested generic, 3 for the second and so ontypeIndexesPerLevel- a map containing the generic index for a given nesting level (may benull)- 返回:
- a
ResolvableTypefor the nested level, orNONE
-
getGeneric
Return aResolvableTyperepresenting the generic parameter for the given indexes. Indexes are zero based; for example given the typeMap<Integer, List<String>>,getGeneric(0)will access theInteger. Nested generics can be accessed by specifying multiple indexes; for examplegetGeneric(1, 0)will access theStringfrom the nestedList. For convenience, if no indexes are specified the first generic is returned.If no generic is available at the specified indexes
NONEis returned.- 参数:
indexes- the indexes that refer to the generic parameter (may be omitted to return the first generic)- 返回:
- a
ResolvableTypefor the specified generic, orNONE - 另请参阅:
-
getGenerics
Return an array ofResolvableTypesrepresenting the generic parameters of this type. If no generics are available an empty array is returned. If you need to access a specific generic consider using thegetGeneric(int...)method as it allows access to nested generics and protects againstIndexOutOfBoundsExceptions.- 返回:
- an array of
ResolvableTypesrepresenting the generic parameters (nevernull) - 另请参阅:
-
resolveGenerics
- 返回:
- an array of resolved generic parameters (the resulting array
will never be
null, but it may containnullelements}) - 另请参阅:
-
resolveGenerics
Convenience method that willgetandresolvegeneric parameters, using the specifiedfallbackif any type cannot be resolved.- 参数:
fallback- the fallback class to use if resolution fails- 返回:
- an array of resolved generic parameters
- 另请参阅:
-
resolveGeneric
- 参数:
indexes- the indexes that refer to the generic parameter (maybe omitted to return the first generic)- 返回:
- a resolved
Classornull - 另请参阅:
-
resolve
Resolve this type to aClass, returningnullif the type cannot be resolved. This method will consider bounds ofTypeVariablesandWildcardTypesif direct resolution fails; however, bounds ofObject.classwill be ignored.If this method returns a non-null
ClassandhasGenerics()returnsfalse, the given type effectively wraps a plainClass, allowing for plainClassprocessing if desirable.- 返回:
- the resolved
Class, ornullif not resolvable - 另请参阅:
-
is
- 从以下版本开始:
- 4.0
-
isCollection
public boolean isCollection()- 从以下版本开始:
- 4.0
-
isMap
public boolean isMap()Is this type aMaptype?- 从以下版本开始:
- 4.0
-
resolve
Resolve this type to aClass, returning the specifiedfallbackif the type cannot be resolved. This method will consider bounds ofTypeVariablesandWildcardTypesif direct resolution fails; however, bounds ofObject.classwill be ignored.- 参数:
fallback- the fallback class to use if resolution fails- 返回:
- the resolved
Classor thefallback - 另请参阅:
-
equals
-
hashCode
public int hashCode() -
toString
Return a String representation of this type in its fully resolved form (including any generic parameters). -
forMethodParameter
Return aResolvableTypefor the specifiedMethodParameter.- 参数:
methodParameter- the source method parameter (must not benull)- 返回:
- a
ResolvableTypefor the specified method parameter - 从以下版本开始:
- 4.0
- 另请参阅:
-
forMethodParameter
public static ResolvableType forMethodParameter(MethodParameter methodParameter, @Nullable ResolvableType implementationType) Return aResolvableTypefor the specifiedMethodParameterwith a given implementation type. Use this variant when the class that declares the method includes generic parameter variables that are satisfied by the implementation type.- 参数:
methodParameter- the source method parameter (must not benull)implementationType- the implementation type- 返回:
- a
ResolvableTypefor the specified method parameter - 从以下版本开始:
- 4.0
- 另请参阅:
-
forMethodParameter
public static ResolvableType forMethodParameter(MethodParameter methodParameter, @Nullable Type targetType) Return aResolvableTypefor the specifiedMethodParameter, overriding the target type to resolve with a specific given type.- 参数:
methodParameter- the source method parameter (must not benull)targetType- the type to resolve (a part of the method parameter's type)- 返回:
- a
ResolvableTypefor the specified method parameter - 从以下版本开始:
- 4.0
- 另请参阅:
-
forMethodParameter
public static ResolvableType forMethodParameter(MethodParameter methodParameter, @Nullable Type targetType, int nestingLevel) Return aResolvableTypefor the specifiedMethodParameterat a specific nesting level, overriding the target type to resolve with a specific given type.- 参数:
methodParameter- the source method parameter (must not benull)targetType- the type to resolve (a part of the method parameter's type)nestingLevel- the nesting level to use- 返回:
- a
ResolvableTypefor the specified method parameter - 从以下版本开始:
- 4.0
- 另请参阅:
-
forParameter
Return aResolvableTypefor the specifiedExecutableparameter.- 参数:
executable- the source Executable (must not benull)parameterIndex- the parameter index- 返回:
- a
ResolvableTypefor the specified method parameter - 另请参阅:
-
forReturnType
Return aResolvableTypefor the specifiedMethodreturn type.- 参数:
method- the source for the method return type- 返回:
- a
ResolvableTypefor the specified method return - 另请参阅:
-
forReturnType
Return aResolvableTypefor the specifiedMethodreturn type. Use this variant when the class that declares the method includes generic parameter variables that are satisfied by the implementation class.- 参数:
method- the source for the method return typeimplementationClass- the implementation class- 返回:
- a
ResolvableTypefor the specified method return - 另请参阅:
-
forParameter
public static ResolvableType forParameter(Executable executable, int parameterIndex, @Nullable Class<?> implementationClass) Return aResolvableTypefor the specifiedMethodparameter with a given implementation. Use this variant when the class that declares the method includes generic parameter variables that are satisfied by the implementation class.- 参数:
executable- the source method or constructor (must not benull)parameterIndex- the parameter indeximplementationClass- the implementation class- 返回:
- a
ResolvableTypefor the specified method parameter - 另请参阅:
-
fromParameter
Return aResolvableTypefor the specifiedParameter.- 参数:
parameter- the source method parameter (must not benull)- 返回:
- a
ResolvableTypefor the specified method parameter - 另请参阅:
-
fromParameter
public static ResolvableType fromParameter(Parameter parameter, @Nullable ResolvableType implementationType) Return aResolvableTypefor the specifiedParameterwith a given implementation type. Use this variant when the class that declares the method includes generic parameter variables that are satisfied by the implementation type.- 参数:
parameter- the source method parameter (must not benull)implementationType- the implementation type- 返回:
- a
ResolvableTypefor the specified method parameter - 另请参阅:
-
fromParameter
-
fromParameter
Return aResolvableTypefor the specifiedParameter, overriding the target type to resolve with a specific given type.- 参数:
parameter- the source method parameter (must not benull)targetType- the type to resolve (a part of the method parameter's type)- 返回:
- a
ResolvableTypefor the specified method parameter - 另请参阅:
-
fromClass
Return aResolvableTypefor the specifiedClass, using the full generic type information for assignability checks. For example:ResolvableType.fromClass(MyArrayList.class).- 参数:
clazz- the class to introspect (nullis semantically equivalent toObject.classfor typical use cases here)- 返回:
- a
ResolvableTypefor the specified class - 另请参阅:
-
fromRawClass
Return aResolvableTypefor the specifiedClass, doing assignability checks against the raw class only (analogous toClass.isAssignableFrom(java.lang.Class<?>), which this serves as a wrapper for. For example:ResolvableType.fromRawClass(List.class).- 参数:
clazz- the class to introspect (nullis semantically equivalent toObject.classfor typical use cases here)- 返回:
- a
ResolvableTypefor the specified class - 另请参阅:
-
fromClass
Return aResolvableTypefor the specified base type (interface or base class) with a given implementation class. For example:ResolvableType.fromClass(List.class, MyArrayList.class).- 参数:
baseType- the base type (must not benull)implementationClass- the implementation class- 返回:
- a
ResolvableTypefor the specified base type backed by the given implementation class - 另请参阅:
-
fromClassWithGenerics
Return aResolvableTypefor the specifiedClasswith pre-declared generics.- 参数:
clazz- the class (or interface) to introspectgenerics- the generics of the class- 返回:
- a
ResolvableTypefor the specific class and generics - 另请参阅:
-
fromClassWithGenerics
Return aResolvableTypefor the specifiedClasswith pre-declared generics.- 参数:
clazz- the class (or interface) to introspectgenerics- the generics of the class- 返回:
- a
ResolvableTypefor the specific class and generics - 另请参阅:
-
fromInstance
Return aResolvableTypefor the specified instance. The instance does not convey generic information but if it implementsResolvableTypeProvidera more preciseResolvableTypecan be used than the simple one based on theClass instance.- 参数:
instance- the instance- 返回:
- a
ResolvableTypefor the specified instance - 另请参阅:
-
fromField
Return aResolvableTypefor the specifiedField.- 参数:
field- the source field- 返回:
- a
ResolvableTypefor the specified field - 另请参阅:
-
fromField
Return aResolvableTypefor the specifiedFieldwith a given implementation.Use this variant when the class that declares the field includes generic parameter variables that are satisfied by the implementation class.
- 参数:
field- the source fieldimplementationClass- the implementation class- 返回:
- a
ResolvableTypefor the specified field - 另请参阅:
-
fromField
Return aResolvableTypefor the specifiedFieldwith a given implementation.Use this variant when the class that declares the field includes generic parameter variables that are satisfied by the implementation type.
- 参数:
field- the source fieldimplementationType- the implementation type- 返回:
- a
ResolvableTypefor the specified field - 另请参阅:
-
fromField
Return aResolvableTypefor the specifiedFieldwith the given nesting level.- 参数:
field- the source fieldnestingLevel- the nesting level (1 for the outer level; 2 for a nested generic type; etc)- 另请参阅:
-
fromField
Return aResolvableTypefor the specifiedFieldwith a given implementation and the given nesting level.Use this variant when the class that declares the field includes generic parameter variables that are satisfied by the implementation class.
- 参数:
field- the source fieldnestingLevel- the nesting level (1 for the outer level; 2 for a nested generic type; etc)implementationClass- the implementation class- 返回:
- a
ResolvableTypefor the specified field - 另请参阅:
-
fromArrayComponent
Return aResolvableTypeas a array of the specifiedcomponentType.- 参数:
componentType- the component type- 返回:
- a
ResolvableTypeas an array of the specified component type
-
fromType
Return aResolvableTypefor the specifiedType.Note: The resulting
ResolvableTypeinstance may not beSerializable.- 参数:
type- the source type (potentiallynull)- 返回:
- a
ResolvableTypefor the specifiedType - 另请参阅:
-
fromType
Return aResolvableTypefor the specifiedTypebacked by the given owner type.Note: The resulting
ResolvableTypeinstance may not beSerializable.- 参数:
type- the source type ornullowner- the owner type used to resolve variables- 返回:
- a
ResolvableTypefor the specifiedTypeand owner - 另请参阅:
-
fromType
Return aResolvableTypefor the specifiedTypeReference.Note: The resulting
ResolvableTypeinstance may not beSerializable.- 参数:
typeReference- the reference to obtain the source type from- 返回:
- a
ResolvableTypefor the specifiedTypeReference - 另请参阅:
-
valueOf
public static ResolvableType valueOf(@Nullable Type type, @Nullable ResolvableType.VariableResolver variableResolver) - 参数:
type- the source type ornullvariableResolver- the variable resolver ornull- 返回:
- a
ResolvableTypefor the specifiedTypeandResolvableType.VariableResolver
-
valueOf
public static ResolvableType valueOf(@Nullable Type type, @Nullable cn.taketoday.core.SerializableTypeWrapper.TypeProvider typeProvider, @Nullable ResolvableType.VariableResolver variableResolver) - 参数:
type- the source type ornulltypeProvider- the type provider ornullvariableResolver- the variable resolver ornull- 返回:
- a
ResolvableTypefor the specifiedTypeandResolvableType.VariableResolver
-
clearCache
public static void clearCache()Clear the internalResolvableType/SerializableTypeWrappercache.
-