KeyValueOf<K, V> constructor

const KeyValueOf<K, V>([
  1. String? kPkg,
  2. String? vPkg
])

KeyValueOf Annotation

A reflectable annotation used to declare a key-value type relationship, such as for maps, configuration entries, or type-safe dictionaries.

Purpose

  • Provides explicit metadata about both key and value types.
  • Supports optional package scoping for each type.
  • Used by dependency resolution or serialization frameworks where generic type information is erased at runtime.

Behavior

  • Stores optional kPkg and vPkg (package names for key and value).
  • Exposes getKey and getValue to resolve Class<K> and Class<V>.

Example

@KeyValueOf("com.example.keys", "com.example.values")
final KeyValueOf<String, User> userMapping = KeyValueOf();

final keyClass = userMapping.getKey();
final valueClass = userMapping.getValue();
print(keyClass.getQualifiedName());   // com.example.keys.String
print(valueClass.getQualifiedName()); // com.example.values.User

Notes

  • Provides strong typing for frameworks handling generic maps.
  • Useful for reflection-based object factories and parsers.

Implementation

const KeyValueOf([this.kPkg, this.vPkg]);