Package io.micronaut.core.reflect
Class GenericTypeUtils
java.lang.Object
io.micronaut.core.reflect.GenericTypeUtils
Utility methods for dealing with generic types via reflection. Generally reflection is to be avoided in Micronaut. Hence,
this class is regarded as internal and used for only certain niche cases.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionresolveGenericTypeArgument
(Field field) Resolves a single generic type argument for the given field.resolveInterfaceTypeArgument
(Class<?> type, Class<?> interfaceType) Resolves a single type argument from the given interface of the given class.static Class<?>[]
resolveInterfaceTypeArguments
(Class<?> type, Class<?> interfaceType) Resolve all type arguments for the given interface from the given type.resolveSuperGenericTypeArgument
(Class<?> type) Resolves a single generic type argument from the super class of the given type.static Class<?>[]
resolveSuperTypeGenericArguments
(Class<?> type, Class<?> superTypeToResolve) Resolve all type arguments for the given super type from the given type.static Class<?>[]
resolveTypeArguments
(Type genericType) Resolves the type arguments for a generic type.
-
Constructor Details
-
GenericTypeUtils
public GenericTypeUtils()
-
-
Method Details
-
resolveGenericTypeArgument
Resolves a single generic type argument for the given field.- Parameters:
field
- The field- Returns:
- The type argument or
Optional.empty()
-
resolveInterfaceTypeArguments
Resolve all type arguments for the given interface from the given type. Also searches superclasses.- Parameters:
type
- The type to resolve frominterfaceType
- The interface to resolve from- Returns:
- The type arguments to the interface
-
resolveSuperTypeGenericArguments
public static Class<?>[] resolveSuperTypeGenericArguments(Class<?> type, Class<?> superTypeToResolve) Resolve all type arguments for the given super type from the given type.- Parameters:
type
- The type to resolve fromsuperTypeToResolve
- The suepr type to resolve from- Returns:
- The type arguments to the interface
-
resolveSuperGenericTypeArgument
Resolves a single generic type argument from the super class of the given type.- Parameters:
type
- The type to resolve from- Returns:
- A single Class or null
-
resolveTypeArguments
Resolves the type arguments for a generic type.- Parameters:
genericType
- The generic type- Returns:
- The type arguments
-
resolveInterfaceTypeArgument
public static Optional<Class<?>> resolveInterfaceTypeArgument(Class<?> type, Class<?> interfaceType) Resolves a single type argument from the given interface of the given class. Also searches superclasses.- Parameters:
type
- The type to resolve frominterfaceType
- The interface to resolve for- Returns:
- The class or null
-