Package io.activej.inject
Class Key<T>
java.lang.Object
io.activej.inject.Key<T>
- Direct Known Subclasses:
Key.KeyImpl
The key defines an identity of a binding. In any DI, a key is usually a type of the object along
with some optional tag to distinguish between bindings which make objects of the same type.
In ActiveJ Inject, a key is also a type token - special abstract class that can store type information with the shortest syntax possible in Java.
For example, to create a key of type Map<String, List<Integer>>, you can just use
this syntax: new Key<Map<String, List<Integer>>>(){}.
If your types are not known at compile time, you can use Types.parameterizedType(java.lang.reflect.Type, java.lang.reflect.Type, java.lang.reflect.Type[]) to make a
parameterized type and give it to a Key.ofType constructor.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns an underlying type with display string formatting (package names stripped) and prepended qualifier display string if this key has a qualifier.@Nullable ObjectA shortcut for.Types.getRawType(Type)(key.getType())getType()<U> Key<U>getTypeParameter(int index) Returns a type parameter of the underlying type wrapped as a key with no qualifier.inthashCode()static <T> Key<T>static <T> Key<T>static <T> Key<T>static <T> Key<T>Returns a new key with same type but the qualifier replaced with a given onetoString()
-
Constructor Details
-
Key
protected Key() -
Key
-
-
Method Details
-
of
-
of
-
ofType
-
ofType
-
qualified
Returns a new key with same type but the qualifier replaced with a given one -
getType
-
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
-
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
-