anonymous-dev
anonymous-dev

Reputation: 3499

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

In dart you can do

class Preference<T extends int>

to define a type constraint. But is there a way to define multiple constrains?

I tried

class Preference<T extends int, String>

But an error get's thrown when I try to pass a argument of type T to a function that excepts a String saying

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

Upvotes: 2

Views: 257

Answers (1)

lrn
lrn

Reputation: 71713

No, Dart type parameters can only have a single constraint. There is no workaround.

Upvotes: 7

Related Questions