是否可以对泛型类型进行多种类型约束?

Is it possible to have multiple type constaints on a generic type?

在 dart 中你可以做到

class Preference<T extends int>

定义类型约束。但是有没有办法定义多个约束?

我试过了

class Preference<T extends int, String>

但是当我尝试将 T 类型的参数传递给除字符串 saying

之外的函数时,会抛出错误

The argument type 'T' can't be assigned to the parameter type 'String'

不可以,Dart 类型参数只能有一个约束。没有解决方法。