Class TypeLiteral<T>
java.lang.Object
build.codemodel.dependency.injection.TypeLiteral<T>
- Type Parameters:
T- the type being captured
Captures a fully-parameterized generic
Type (e.g. List<Person>) that would otherwise be lost
to erasure, allowing it to be used as a binding key.
Create a TypeLiteral using an anonymous subclass, so the compiler retains the type argument in the
generated class's Class.getGenericSuperclass():
List<Person> people = new ArrayList<>();
// ... adding some people ...
binder.bind(new TypeLiteral<List<Person>>() {}).to(people);
- Since:
- Apr-2026
- Author:
- brian.oliver
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs aTypeLiteral, capturing the type argument supplied by an anonymous subclass. -
Method Summary
-
Constructor Details
-
TypeLiteral
protected TypeLiteral()Constructs aTypeLiteral, capturing the type argument supplied by an anonymous subclass.- Throws:
IllegalArgumentException- if constructed directly (not as an anonymous subclass) or without a concrete type argument
-
-
Method Details
-
type
-