- java.lang.Object
-
- com.rezzedup.util.constants.types.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 TypeCapture<>() {};
-
-
Constructor Summary
Constructors Constructor Description TypeCapture()Automatically retrieves type information based on reified generic types (only applicable for subclasses with explicitly declared type parameters).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static TypeCapture<Object>any()Gets the constantObjecttype capture.booleanequals(@NullOr Object o)List<TypeCapture<?>>generics()Gets the captured generic type parameters.inthashCode()booleanisGeneric()Checks if generic type parameters are captured or not.booleanisWildcard()Checks if the captured type is a wildcard (?) or not.Class<? super T>raw()Gets the "raw" type, or, in other words: its direct, non-generic class.StringtoString()Typetype()Gets the underlying type.static <T> TypeCapture<T>type(TypeCompatible<T> type)Converts an alternative compatible type token into a type captures.static <T> TypeCapture<T>type(Class<T> type)Captures the type directly from a non-generic class.static TypeCapture<?>type(Type type)Captures an unknown type.
-
-
-
Method Detail
-
any
public static TypeCapture<Object> any()
Gets the constantObjecttype 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
-
type
public final Type type()
Description copied from interface:TypeCompatibleGets the underlying type.- Specified by:
typein interfaceTypeCompatible<T>- Returns:
- the 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:
trueif generic type parameters are captured, otherwisefalse
-
isWildcard
public final boolean isWildcard()
Checks if the captured type is a wildcard (?) or not.- Returns:
trueif the captured type is an instance ofWildcardType, otherwisefalse
-
-