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?

有帮助吗?

解决方案

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
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top