ParameterizedTypeReference<T> class
abstract
A runtime type reference for capturing and working with parameterized/generic types.
This class solves the Dart limitation where List<String>.runtimeType
loses
generic type arguments. By creating a subclass (typically anonymous), the type
information is preserved at runtime.
Usage
Basic Usage
final listRef = ParameterizedTypeReference<List<String>>();
print(listRef.getType()); // List<String>
With Complex Types
final complexRef = ParameterizedTypeReference<Map<String, List<int>>>();
print(complexRef.getType()); // Map<String, List<int>>
With ResolvableType
final ref = ParameterizedTypeReference<Set<double>>();
final resolvable = ref.getResolvableType();
print(resolvable.genericParameters[0].type); // double
Implementation Notes
- Always create as an anonymous subclass using the factory constructor
- The actual type capture happens through Dart's type inference
- Works with nested generic types (e.g.,
Map<String, List<int>>
)
- Annotations
-
- @Generic(ParameterizedTypeReference)
Constructors
- ParameterizedTypeReference()
-
Creates a type reference that captures the generic type parameter.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
getResolvableType(
) → ResolvableType - Returns a ResolvableType representation of the captured type.
-
getType(
) → Type - Returns the captured generic type with all type arguments preserved.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited