Class TypeRef<T>
java.lang.Object
me.datafox.dfxengine.injector.api.TypeRef<T>
Represents a type with parameters. This class is used when requesting
Components from the
Injector. As an example, if you wanted to reference Component<Type1,Type2<Type3>>, you would call
TypeRef.of(Component.class, TypeRef.of(Type1.class), TypeRef.of(Type2.class, TypeRef.of(Type3.class)));. The
constructor checks for parameter count and throws an exception if an invalid amount of type parameters.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionobject()static <T> TypeRef<T> static <T> TypeRef<T> static <T> TypeRef<T> static <T> TypeRef<T> static <T> TypeRef<T> static <T> TypeRef<T> toString()TypeRef<?> uncast()The purpose of this method is to be able to cast a type reference to a parameterised type with multiple type layers without the compiler complaining about illegal casting.
-
Constructor Details
-
TypeRef
Constructs a type reference- Parameters:
type- type to be representedsup-trueif this type reference refers to? super Tparameters- type parameters to be represented- Throws:
ParameterCountMismatchException- if the amount of parameters for the specified type is different to the amount of provided parameters
-
-
Method Details
-
uncast
The purpose of this method is to be able to cast a type reference to a parameterised type with multiple type layers without the compiler complaining about illegal casting. For example, callingTypeRef.of(Map.class, String.class, Integer.class)will return an object with typeTypeRef<Map>without the parameters forMap, and casting that directly toTypeRef<Map<String,Integer>>is not allowed. But casting fromTypeRef<?>is allowed, so calling(TypeRef<Map<String,Integer>>) TypeRef.of(Map.class, String.class, Integer.class).uncast()will work. This is mainly useful for getting the component with the right runtime type withInjector.getComponent(TypeRef)and related methods.- Returns:
- this type reference as
TypeRef<?>
-
toStringWithoutPackage
- Returns:
- String representation of this type reference in the format "
Type<Parameter,Other<Child>>" without packages
-
toStringParametersWithoutPackage
- Returns:
- String representation of this type reference in the format "
Type<Parameter,Other<Child>>" with the parameters without packages
-
toString
-
object
- Returns:
- type reference for
Object
-
of
- Type Parameters:
T- type for the type reference- Parameters:
type- type for the type referenceparameters- parameters for the type reference- Returns:
- type reference for the specified parameters
-
of
- Type Parameters:
T- type for the type reference- Parameters:
type- type for the type referencesup-trueif the type reference refers to? super Tparameters- parameters for the type reference- Returns:
- type reference for the specified parameters
-
of
- Type Parameters:
T- type for the type reference- Parameters:
type- type for the type referenceparameters- parameters for the type reference- Returns:
- type reference for the specified parameters
-
of
- Type Parameters:
T- type for the type reference- Parameters:
type- type for the type referencesup-trueif the type reference refers to? super Tparameters- parameters for the type reference- Returns:
- type reference for the specified parameters
-
of
- Type Parameters:
T- type for the type reference- Parameters:
type- type for the type referencefirstParameter- first parameter for the type referenceparameters- other parameters for the type reference- Returns:
- type reference for the specified parameters
-
of
public static <T> TypeRef<T> of(Class<T> type, boolean sup, Class<?> firstParameter, Class<?>... parameters) - Type Parameters:
T- type for the type reference- Parameters:
type- type for the type referencesup-trueif the type reference refers to? super TfirstParameter- first parameter for the type referenceparameters- other parameters for the type reference- Returns:
- type reference for the specified parameters
-