Class GenericTypeUtils

java.lang.Object
io.micronaut.core.reflect.GenericTypeUtils

public class GenericTypeUtils extends Object
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 Details

    • GenericTypeUtils

      public GenericTypeUtils()
  • Method Details

    • resolveGenericTypeArgument

      public static Optional<Class<?>> resolveGenericTypeArgument(Field field)
      Resolves a single generic type argument for the given field.
      Parameters:
      field - The field
      Returns:
      The type argument or Optional.empty()
    • resolveInterfaceTypeArguments

      public static Class<?>[] resolveInterfaceTypeArguments(Class<?> type, Class<?> interfaceType)
      Resolve all type arguments for the given interface from the given type. Also searches superclasses.
      Parameters:
      type - The type to resolve from
      interfaceType - 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 from
      superTypeToResolve - The suepr type to resolve from
      Returns:
      The type arguments to the interface
    • resolveSuperGenericTypeArgument

      public static Optional<Class<?>> resolveSuperGenericTypeArgument(Class<?> type)
      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

      public static Class<?>[] resolveTypeArguments(Type genericType)
      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 from
      interfaceType - The interface to resolve for
      Returns:
      The class or null