Pergunta

I would like to use the nested Generics, like

class Class<List<T>> {
...
}

But always Dart Editor gives me alerts. How should I avoid these alerts?

Foi útil?

Solução

Well, Dart Editor is right. This code doesn't make any sense. Without further information on what you are trying to do (don't hesitate to update your question), I am assuming you actually mean one of those:

class MyClass<T> {
  List<T> listField;
  // other stuff
}

Or maybe the list itself should be generic?

void main() {
  MyClass<SomeCustomListClass<String>> instance = new MyClass();
}

class MyClass<T extends List<String>> {
  T listField;
  // ...
}

Or maybe everything has to be generic:

void main() {
  MyClass<String, SomeCustomListClass<String>> instance = new MyClass();
}

class MyClass<TElement, TList extends List<TElement>> {
  TList listField;
  TElement _firstListElement;
  // whatever that could be used for
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top