Tien Do Nam
Tien Do Nam

Reputation: 4440

Dart: How do I define nested generics?

I have the following classes (see below). How can I put one generic type into another generic?

class MySet<T> extends MyCollection<T>{}

class MyList<T> extends MyCollection<T>{}

class MyCollection<T> {}

// It works but MyCollection has no type
class MyProvider<C extends MyCollection> {}

// It does not work. What is the correct way here?
class MyProvider<C extends MyCollection<T>> {}

Upvotes: 5

Views: 540

Answers (1)

George Rabbat
George Rabbat

Reputation: 578

You have to define second generic type first, Then use it in nested generic class:

    //Define T as second generic type
    class MyProvider<T,C extends MyCollection<T>> {}

Upvotes: 4

Related Questions