0
我有一个字符串映射到Dart类型的例子, animals = <String, Type>{'cat':CatType, 'dog':DogType}
我在运行时修改。有没有一种方法可以确保添加到此映射的类型在编译时或运行时实现特定的接口?喜欢的东西强制执行Dart类型实现接口
animals = <String, Type<? implements AnimalType>>{...}
或运行期间,
void register(name, type):
if type implements AnimalType:
animals[name] = type