Why can't i use Type variable as a Type parameter to a generic class
This is not possible in Dart as it stands today.
Parameterized types (things like List<int>
) can take literal types (e.g., List<Chicken>
) or type
parameters (e.g., List<T>
where T
is declared as a type
parameter in a generic, as it in Cage) as arguments. They cannot take arbitrary expressions, even if those are of type Type
.
A variable such as t
might hold a Type
(as in your example) but in general it is really hard to be sure of that. It could just as easily hold a non-type value such as the number 3, because Dart's type system does not guarantee that something with static type Type really is a Type
.
If we let these through, the system would be thoroughly corrupted. We could add runtime checks for that, but that would hit performance.