Home > Enterprise >  Dart: How do I define nested generics?
Dart: How do I define nested generics?

Time:05-06

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>> {}

CodePudding user response:

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>> {}
  • Related