public class GuavaGenericsResolver extends Object implements GenericsResolver
GuavaGenericsResolver
implementation using Guava.GenericsResolver.Provider
Constructor and Description |
---|
GuavaGenericsResolver() |
Modifier and Type | Method and Description |
---|---|
Class |
asClass(Type actualType)
Get the class represented by the reflected type.
|
Type |
extractActualType(Type containingType,
Field field)
Analyzes the method in the context of containingClass and returns the Class that is represented by
the method's generic return type.
|
Type |
extractActualType(Type containingType,
Method method)
Analyzes the method in the context of containingClass and returns the Class that is represented by
the method's generic return type.
|
Class |
extractGenericFieldType(Class containingClass,
Field field)
Analyzes the field in the context of containingClass and returns the Class that is represented by
the field's generic type.
|
Class<?> |
extractGenericReturnType(Class<?> containingClass,
Method method)
Analyzes the method in the context of containingClass and returns the Class that is represented by
the method's generic return type.
|
Type |
resolve(Type type,
Type containingType)
Resolves the type parameter based on the context of the containingType.
|
public GuavaGenericsResolver()
public Class<?> extractGenericReturnType(Class<?> containingClass, Method method)
GenericsResolver
GenericsResolver.extractActualType(java.lang.reflect.Type, java.lang.reflect.Method)
.extractGenericReturnType
in interface GenericsResolver
containingClass
- class which either contains or inherited the methodmethod
- method from which to extract the return typeGenericsResolver.resolve(java.lang.reflect.Type,java.lang.reflect.Type)
,
GenericsResolver.asClass(java.lang.reflect.Type)
public Class extractGenericFieldType(Class containingClass, Field field)
GenericsResolver
extractGenericFieldType
in interface GenericsResolver
containingClass
- class which either contains or inherited the fieldfield
- field from which to extract the typeGenericsResolver.extractActualType(java.lang.reflect.Type, java.lang.reflect.Field)
,
GenericsResolver.resolve(java.lang.reflect.Type,java.lang.reflect.Type)
,
GenericsResolver.asClass(java.lang.reflect.Type)
public Type extractActualType(Type containingType, Method method)
GenericsResolver
extractActualType
in interface GenericsResolver
containingType
- Type which is/represents the class that either contains or inherited the methodmethod
- method from which to extract the generic return typeGenericsResolver.resolve(java.lang.reflect.Type,java.lang.reflect.Type)
public Type extractActualType(Type containingType, Field field)
GenericsResolver
extractActualType
in interface GenericsResolver
containingType
- Type which is/represents the class that either contains or inherited the fieldfield
- field from which to extract the generic return typeGenericsResolver.resolve(java.lang.reflect.Type,java.lang.reflect.Type)
public Type resolve(Type type, Type containingType)
GenericsResolver
TypeVariable
will be unwrapped to the type argument resolved form the class
hierarchy. This may be something other than a simple Class if the type argument is a ParameterizedType for
instance (e.g. List<E>; List<Map<Long, String>>
, E would be returned as a ParameterizedType with the raw
type Map and type arguments Long and String.resolve
in interface GenericsResolver
type
- the generic type (ParameterizedType, GenericArrayType, WildcardType, TypeVariable) to be resolvedcontainingType
- the type which hispublic Class asClass(Type actualType)
GenericsResolver
TypeVariable
the first bound is returned. If your type variable extends multiple interfaces that information
is lost.
WildcardType
the first lower bound is returned. If the wildcard is defined with upper bounds
then Object
is returned.asClass
in interface GenericsResolver
actualType
- a Class, ParameterizedType, GenericArrayType5.6.3 - Copyright © 2003-2021 The Apache Software Foundation.