Class TypeCapture<T>

  • Type Parameters:
    T - the type
    All Implemented Interfaces:
    TypeCompatible<T>

    public abstract class TypeCapture<T>
    extends Object
    implements TypeCompatible<T>
    A so-called "super" type token capable of capturing generic type information.

    In order to capture generic types, this class must be extended with explicit type parameters. This should typically be done by instantiating an anonymous subclass and assigning it to a constant.

    For example:

     public static final TypeCapture<List<String>> STRING_LIST_TYPE = new TypeCaptur<>() {};
     
    • Constructor Detail

      • TypeCapture

        public TypeCapture()
        Automatically retrieves type information based on reified generic types (only applicable for subclasses with explicitly declared type parameters).
    • Method Detail

      • any

        public static TypeCapture<Object> any()
        Gets the constant Object type capture.
        Returns:
        object class type capture
      • type

        public static <T> TypeCapture<T> type​(Class<T> type)
        Captures the type directly from a non-generic class.
        Type Parameters:
        T - non-generic type
        Parameters:
        type - the class
        Returns:
        the captured type
      • type

        public static TypeCapture<?> type​(Type type)
        Captures an unknown type.
        Parameters:
        type - the unknown type
        Returns:
        the captured type
      • type

        public static <T> TypeCapture<T> type​(TypeCompatible<T> type)
        Converts an alternative compatible type token into a type captures.
        Type Parameters:
        T - generic type
        Parameters:
        type - the compatible type token
        Returns:
        the captured type
      • raw

        public final Class<? super T> raw()
        Gets the "raw" type, or, in other words: its direct, non-generic class.
        Returns:
        the class representing this type
      • generics

        public final List<TypeCapture<?>> generics()
        Gets the captured generic type parameters.
        Returns:
        an immutable list of captured generic type parameters, otherwise empty
      • isGeneric

        public final boolean isGeneric()
        Checks if generic type parameters are captured or not.
        Returns:
        true if generic type parameters are captured, otherwise false
      • isWildcard

        public final boolean isWildcard()
        Checks if the captured type is a wildcard (?) or not.
        Returns:
        true if the captured type is an instance of WildcardType, otherwise false
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class Object