Custom collection in the dart?

I'm trying to figure out how to create a custom collection of custom objects in Dart and have a List as an abstract class, I don't see any other way than to "have" a list in my custom collection:

class MenuItemCollection {

  List<MenuItem> _items;

  MenuItemCollection() {
    _items = new List<MenuItem>();
  }

  List<MenuItem> get items => _items;
}

      

Is there a better way to do this?

+3


source to share


2 answers


You can do something like:



class MenuItemCollection implements List<MenuItem> {
  final _list = new List<MenuItem>();
  MenuItemCollection();

  noSuchMethod(InvocationMirror invocation) => invocation.invokeOn(_list);
}

      

+3


source


you can use

List <E>

Queue <E>

Install <E>



or just an array E[]

The best approach is to use the Collection structure (so the first 3 options). But if you want, you can even make a recursive array.

0


source







All Articles