public class GenericTypes extends Object
| Constructor and Description |
|---|
GenericTypes() |
| Modifier and Type | Method and Description |
|---|---|
static Optional<Type> |
findGenericParameter(Type type,
Class<?> parameterizedSupertype)
For the given type which extends parameterizedSupertype, returns the
first generic parameter for parameterized supertype, if concretely
expressed.
|
static Class<?> |
getErasedType(Type type)
Returns the erased class for the given type.
|
static boolean |
isArray(Type type) |
static Type |
resolveType(Type type,
Type contextType)
Resolves the
type parameter in the context of contextType. |
public static Optional<Type> findGenericParameter(Type type, Class<?> parameterizedSupertype)
Example:
type is ArrayList<String> and
parameterizedSuperType is List.class, returns
Optional.of(String.class).type is ArrayList.class (raw) and
parameterizedSuperType is List.class, returns
Optional.empty().type - the subtype of parameterizedSupertypeparameterizedSupertype - the parameterized supertype from which we want the generic
parameterpublic static Class<?> getErasedType(Type type)
Example: if type is List<String>, returns
List.class
type - the typepublic static boolean isArray(Type type)
Type is an Array type.public static Type resolveType(Type type, Type contextType)
type parameter in the context of contextType. For example, if
type is List.class.getMethod("get", int.class).getGenericReturnType(), and
contextType is List<String>, this method returns String.classtype - the type to be resolved in the scope of contextTypecontextType - the context type in which type is interpreted to resolve the type.Copyright © 2017. All rights reserved.