Package org.apache.maven.di
Class Key<T>
java.lang.Object
org.apache.maven.di.Key<T>
- Type Parameters:
T
- The type this key represents
A binding key that uniquely identifies a dependency in the injection system.
Keys combine a type with an optional qualifier to uniquely identify dependencies within the injection system. They also serve as type tokens, allowing preservation of generic type information at runtime.
Example usage:
// Simple key for a type Key<Service> simple = Key.of(Service.class); // Key with generic type information Key<List<String>> generic = new Key<List<String>>(){}; // Key with qualifier Key<Service> qualified = Key.of(Service.class, "primary");
- Since:
- 4.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns an underlying type with display string formatting (package names stripped) and prepended qualifier display string if this key has a qualifier.Returns the qualifier associated with this key, if any.A shortcut for
.Types.getRawType(Type)
(key.getType())getType()
Returns the actual type represented by this key.<U> Key<U>
getTypeParameter
(int index) Returns a type parameter of the underlying type wrapped as a key with no qualifier.int
hashCode()
static <T> Key<T>
Creates a new Key instance for the specified type.static <T> Key<T>
Creates a new Key instance for the specified type with a qualifier.static <T> Key<T>
static <T> Key<T>
toString()
-
Constructor Details
-
Key
protected Key() -
Key
-
Key
-
-
Method Details
-
of
Creates a new Key instance for the specified type.- Type Parameters:
T
- the type parameter- Parameters:
type
- the Class object representing the type- Returns:
- a new Key instance
- Throws:
NullPointerException
- if type is null
-
of
Creates a new Key instance for the specified type with a qualifier.- Type Parameters:
T
- the type parameter- Parameters:
type
- the Class object representing the typequalifier
- the qualifier object (typically an annotation instance)- Returns:
- a new Key instance
- Throws:
NullPointerException
- if type is null
-
ofType
-
ofType
-
getType
Returns the actual type represented by this key.This includes full generic type information if available.
- Returns:
- the type represented by this key
-
getRawType
A shortcut for
. Also casts the result to a properly parameterized class.Types.getRawType(Type)
(key.getType()) -
getTypeParameter
Returns a type parameter of the underlying type wrapped as a key with no qualifier.- Throws:
IllegalStateException
- when underlying type is not a parameterized one.
-
getQualifier
Returns the qualifier associated with this key, if any.- Returns:
- the qualifier object or null if none exists
-
getDisplayString
Returns an underlying type with display string formatting (package names stripped) and prepended qualifier display string if this key has a qualifier. -
equals
-
hashCode
public int hashCode() -
toString
-