A Dart List is abstract, but it can be instantiated. Why?

Viewed 51

The Iterable Collection docs state the following:

In Dart, an Iterable is an abstract class, meaning that you can’t instantiate it directly. However, you can create a new Iterable by creating a new List or Set.

That makes sense to me. But then I realized, "Wait, List and Set are also abstract." List source code:

abstract class List<E> implements EfficientLengthIterable<E> {

How is it that the Dart analyzer knows I can't do this:

final myIterable = Iterable();

But I can do this:

Iterable<String> myIterable = List<String>.empty();

Is it because Dart follows the exteral factory to some concrete implementation somewhere? List source code:

external factory List.empty({bool growable = false});

I'm trying to understand abstract and concrete classes and how the Dart analyzer knows what error message to give me.

0 Answers
Related