@Generic annotation solves Dart reflection issues where generic types return _ClassMirror instead of usable Type objects, preventing JetLeaf from creating instances or invoking methods reflectively. This occurs because Dart’s type erasure causes generic type parameters to be lost at runtime, and when JetLeaf tries to reflect on classes like List<String>, it receives _ClassMirror instead of a proper Type that can be used for instance creation or method invocation. The annotation provides explicit type metadata that JetLeaf can read at compile time and use at runtime, ensuring that reflection operations work correctly even with complex generic types.
The Problem: _ClassMirror Instead of Type
Without @Generic, JetLeaf gets _ClassMirror for generic types, which cannot be used for reflection operations:
How @Generic Solves This
@Generic provides JetLeaf with the actual Type object, bypassing Dart’s _ClassMirror limitation:
Type Parameter Resolution
@Generic does not resolve type variables like T in User<T>: